Include Foreign Key Properties in DataObjects.Net
-
19-06-2021 - |
Pregunta
I'm recently concerned in the problems we have with Entity Framework and we may need to find a replacement. According to ORMBattle, the best candidate is DataObjects.Net, the result of my initial investigations are very promising, except one feature that we need in our structure:
Consider two classes: Order and Customer, in class "Order" I have a "Customer" navigation property (and probably an "Orders" navigation property in the Customer class). I also need a property CustomerID in class Order. this is totally possible in lowly EF4.
How can I achieve this goal?
Solución
you can add non-persistent property with special getter that does the job:
public long CustomerId
{
get
{
return GetReferenceKey(TypeInfo.Fields["Customer"]).Value.GetValue<long>(0);
}
}
The setter can be added in the same manner.
Hope that helps.
P.S.
This is a copy of the original answer that can be found on the official DataObjects.Net support site.