I am using WCF Data Services 5.0 with the EF DbContext.
I see old articles that say you can use Expand and LoadProperty to get WCF to return related entities in the one request.
The only equivalent I see with DbContext is Include, but that doesn’t seem to work.
Is there any way to load all the related records when working with a DbContext?
I am using the below code (one CategoryGroup can contain many Category entities):
[WebGet]
public IQueryable<CategoryGroup> GetAllCategories(string activationCode)
{
try
{
var db = this.CurrentDataSource;
var licence = db.Licenses
.Include("Contact")
.FirstOrDefault();
if (licence != null)
{
var customerId = licence.Contact.CustomerId;
return db.CategoryGroups.Include("Categories").Where(r => r.CustomerId == customerId);
}
}
catch(Exception ex)
{
}
return new List<CategoryGroup>().AsQueryable();
}
This function only returns the CategoryGroup entities (without related Category entities) in the OData format.
Currently the WCF DS server can’t auto-expand. So having the Include in the code above has no effect on the response from the service operation. Expansions can only be requested by the client through the $expand query option.