title: Entity Framework: Issue with lazy load "solution" (Not asking how to do lazy loading)
body: <p>So basically I came up with a semi home grown solution to lazy loading by basically having generated property be private and have a public property that dealt with whether to load the generated property:</p>
  
  <pre><code> public ChatRoom ParentRoom
   {
     get
     {
       if(!ParentRoomInnerReference.IsLoaded)
       {
          ParentRoomInnerReference.Load();
       }
  
       return ParentRoomInner;
     }   
  
     set
     {
       ParentRoomInner = value;  
     }
   }
  </code></pre>
  
  <p>Now this works well with queries in the class (as I have all "queries" with in a partial class extension of the generated class) by something like:</p>
  
  <pre><code> context.Items.Where(ParentRoomInner.Id = someId).ToList();
  </code></pre>
  
  <p>As this method is inside the Item class, it can run this just fine where as it can't do:</p>
  
  <pre><code> context.Items.Where(ParentRoom.Id = someId).ToList();
  </code></pre>
  
  <p>Since entity framework can't figure out what that proxy property is in order to generate the expression.  This really becomes a problem is say I am trying to get a count of all posts (Items) for a room, and I want that method on the Room class.</p>
  
  <pre><code> public Int32 GetPostCount()
   {
      return EntityContext.Context
             .ChatItems
             .Count(item =&gt; item.ParentRoom.ChatRoomID == ChatRoomID); //Boom
   }
  </code></pre>
  
  <p>For the same reason within the Item class I can't use the ParentRoom (proxy) property within the Item class, I can't use it in this query for the Room class.  Entity framework just can't figure out that property.</p>
  
  <p>Now question is, is there some kind of attribute I might be able to tag the ParentRoom property so that it knows that is refers to the ParentRoomInner property and therefore can know how to handle it when breaking down the expression?</p>
  
  <p>The only other alternatives I can think of are having the generated property be internal and have the Room class query use the ParentRoomInner property (meh) or moving methods like the GetPostCount method to the Item class and just have the GetPostCount method on the Room class point to it.  (Not terrible either but just doubles up a method)</p>