Best Way to Add Sublist in EF
My database model has the following
Users(table) related to orders(table) related to order line items(table)
I would like to have a navigational property for order line items mapped to the user, however I don't want to have to setup a user_id and foreign key on t开发者_StackOverflow中文版he order line items table - is there a way I can do this via EF - i'd rather just somehow connect it via the fact that the user is tied to the order table - and that assumes that the user is tied to all those order line items?
I'm using EF v4
I can't see why you wouldn't want the foreign key, but If you go into the model viewer and right click on the entity name you can choose add-> association to manually add one in.
You could just create a partial class for the OrderLine entity and add a property called User. Implement the user property to automatically return the user object via the Order entity.
For example (vb):
Partial Public Class OrderLine
Public Readonly Property User As User
Get
Return Me.Order.User
End Get
End Property
End Class
精彩评论