title: Can I create nested classes when using Linq-To-Entities?
body: <p>I'm still learning Entity Framework and Linq-To-Entities, and I was wondering if a statement of this kind is possible:</p>
  
  <pre><code>using (var context = new MyEntities())
  {
      return (                    
          from a in context.ModelSetA.Include("ModelB")
          join c in context.ModelSetC on a.Id equals c.Id
          join d in context.ModelSetD on a.Id equals d.Id
          select new MyModelA()
          {
              Id = a.Id,
              Name = a.Name,
              ModelB = new MyModelB() { Id = a.ModelB.Id, Name = a.ModelB..Name },
              ModelC = new MyModelC() { Id = c.Id, Name = c.Name },
              ModelD = new MyModelD() { Id = d.Id, Name = d.Name }
          }).FirstOrDefault();
  }
  </code></pre>
  
  <p>I have to work with a pre-existing database structure, which is not very optimized, so I am unable to generate EF models without a lot of extra work. I thought it would be easy to simply create my own Models and map the data to them, but I keep getting the following error:</p>
  
  <blockquote>
    <p>Unable to create a constant value of type 'MyNamespace.MyModelB'. Only
    primitive types ('such as Int32, String, and Guid') are supported in
    this context.</p>
  </blockquote>
  
  <p>If I remove the mapping for ModelB, ModelC, and ModelD it runs correctly. Am I unable to create new nested classes with Linq-To-Entities? Or am I just writing this the wrong way?</p>