Answered by:
EF CTP5 : Eager loading of a property of an entity

Question
-
Hello,
Not sure if this can be done in EF, but I have the following 2 entities :
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public int AddressId { get; set; }
public Address Address { get; set; }
}public class Address
{
public int Id { get; set; }
public string Street { get; set; }
}What I want to do is whenever I refer to the entity Person, I want its Address property to be loaded automatically (INNER JOIN). The main reason I want this is because we want from oData whenever we browse to http://.../..svc/Persons to load the address information instead of having to do http://.../..svc/Persons?$expand=Address
I'ts something I want to do because the oData feed from NetFlix seems to be able to do that, but i'm pretty sure the back-end is not EF CTP5.
thank you,
JS
Friday, January 14, 2011 8:32 PM
Answers
-
i am not sure about the odata but in general if u access the property for the address first time, it will be loaded for u if u have lazy loading turned on. other option u have is egare loading.
The last option i see is entity splitting where an entity is mapped to multiple tables like Person table and address table. but in that case all the address information must reside in the Person entity but u map it to address table or u can expose a complex type property address map it that way. The database constraint for this option is, both address and person must have the same primary key
These are possible options i know.
Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani- Proposed as answer by Arthur Vickers - MSFTModerator Sunday, January 16, 2011 5:06 AM
- Marked as answer by masterjs Monday, January 17, 2011 4:23 PM
Friday, January 14, 2011 9:23 PM -
Masterjs,
Other than the things Zeeshan suggested I don’t think there is a way to do what you want without using “expand”. It might be worth asking on the Data Services forum as well.
Thanks,
Arthur
- Proposed as answer by Arthur Vickers - MSFTModerator Sunday, January 16, 2011 5:06 AM
- Marked as answer by masterjs Monday, January 17, 2011 4:23 PM
Sunday, January 16, 2011 5:05 AMModerator
All replies
-
i am not sure about the odata but in general if u access the property for the address first time, it will be loaded for u if u have lazy loading turned on. other option u have is egare loading.
The last option i see is entity splitting where an entity is mapped to multiple tables like Person table and address table. but in that case all the address information must reside in the Person entity but u map it to address table or u can expose a complex type property address map it that way. The database constraint for this option is, both address and person must have the same primary key
These are possible options i know.
Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani- Proposed as answer by Arthur Vickers - MSFTModerator Sunday, January 16, 2011 5:06 AM
- Marked as answer by masterjs Monday, January 17, 2011 4:23 PM
Friday, January 14, 2011 9:23 PM -
Masterjs,
Other than the things Zeeshan suggested I don’t think there is a way to do what you want without using “expand”. It might be worth asking on the Data Services forum as well.
Thanks,
Arthur
- Proposed as answer by Arthur Vickers - MSFTModerator Sunday, January 16, 2011 5:06 AM
- Marked as answer by masterjs Monday, January 17, 2011 4:23 PM
Sunday, January 16, 2011 5:05 AMModerator -
Alright!
Thanks guys! Not the answer I wanted to ear, but at least I won't loose anymore time on that "request"! ;o)
JS
Monday, January 17, 2011 3:48 PM