Note that there are some explanatory texts on larger screens.

plurals
  1. POContext.CreateQuery<T> is loading everything?
    primarykey
    data
    text
    <p>I have been working away for EF4 and got a lot of stuff done and its working really nicely, the one problem I do have is: Context.CreateQuery returns correctly, but it is also loading ALL its related entities too!? </p> <p>Which is going to cause massive issues once the DB actually has real data in there.</p> <p>Any ideas on how to stop it from loading all the related entities?</p> <p>Here is snippet of what I have:</p> <p>The original call:</p> <pre><code>public ObjectNameHere GetById(Guid id) { return Query(p =&gt; p.Id == id).SingleOrDefault(); } </code></pre> <p>The Provider Base</p> <pre><code>private static Type GetBaseType(Type type) { var baseType = type.BaseType; if (baseType != null &amp;&amp; baseType != typeof(EntityObject)) { return GetBaseType(type.BaseType); } return type; } private static bool HasBaseType(Type type, out Type baseType) { var originalType = type.GetType(); baseType = GetBaseType(type); return baseType != originalType; } private IQueryable&lt;T&gt; CreateQuery&lt;T&gt;() { Type baseType; return HasBaseType(typeof(T), out baseType) ? Context.CreateQuery&lt;T&gt;(ProviderHelper.GetEntitySetName(Context, baseType.Name)).OfType&lt;T&gt;() : Context.CreateQuery&lt;T&gt;(ProviderHelper.GetEntitySetName(Context, baseType.Name)); } </code></pre> <p>The Provider Helper</p> <pre><code> public static string GetChildTypeNames(Type[] childTypes) { var context = ContextProvider.Context; var childNames = new StringBuilder(); for (var i = 0; i &lt; childTypes.Count(); i++) { childNames.Append(GetEntitySetName(context,childTypes[i].Name)); if (i != childTypes.Count()) { childNames.Append("."); } } return childNames.ToString(); } public static string GetEntitySetName(ObjectContext context, string entityTypeName) { var container = context.MetadataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace); return (from meta in container.BaseEntitySets where meta.ElementType.Name == entityTypeName select meta.Name).FirstOrDefault(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload