I am using VS2010.Net4 Linq-to-EntityFramework and would like to explicitly load some child data. I would like to provide functionality similar to the DataLoadOptions or LoadWith functions that are available for Linq-to-SQL IIUC but not available for Linq-to-EF.
(Aside, this is so that I can record data that will be played back later during testing. We used lazy loading and I need to find these occurrences and replace with impatience loading. DataLoadOptions would allow this method to be implemented.)
I am trying to provide a download scheme with the type of electronic download described in the MosesOfEgypt blog . I changed the generation of T4 and have what, in my opinion, is the last issue. In .Net4, object properties return an ObjectSet . But unfortunately, the Include function returns ObjectQuery , which is the base class for the ObjectSet .
Here is a subset of the ObjectContext class created from a modified T4 template:
#region DataLoadOptions Functionality
public DataLoadOptions LoadOptions { get; set; }
private ObjectSet<TEntity> ApplyDataLoadOptions<TEntity>(string queryString) where TEntity : class
{
var query = CreateObjectSet<TEntity>(queryString);
if (LoadOptions != null)
{
var members = LoadOptions.GetPreloadedMembers<TEntity>();
foreach (var member in members)
{
********** query = query.Include(member.Name);
}
}
return query;
}
#endregion
#region ObjectSet Properties
public ObjectSet<Address> Addresses
{
get
{
if ((_Addresses == null))
{
_Addresses = ApplyDataLoadOptions<Address>("Addresses");
}
return _Addresses;
}
}
#endregion
, " *", - , ObjectQuery ObjectSet. ANd upcast, , , , .
ObjectSet.Include, ObjectSet ObjectQuery. , ObjectQuery.Include, . , .
, ObjectQuery ObjectSet. , , .
DataLoadOptions Linq-to-EF .Net4 .