title: Create DTO by joining EF entity with another object in LINQ
body: <p>I have an Entity Framework entity</p>
  
  <pre><code>public class Entiy 
  {
      public string EntityProperty1 { get; set; }
      public string EntityProperty2 { get; set; }
      public string EntityProperty3 { get; set; }
      public Guid? SomeId { get; set; }
  }
  </code></pre>
  
  <p>And also an OtherObject and a DTO which contains properties that'd be equal to the other classes.</p>
  
  <pre><code>public class OtherObject
  {
      public string OtherObjectProperty1 { get; set; }
      public string OtherObjectProperty2 { get; set; }
      public string OtherObjectProperty3 { get; set; }
      public Guid SomeId { get; set; }
  }
  
  public class DTO
  {
      public string EntityProperty1 { get; set; }
      public string EntityProperty2 { get; set; }
      public string EntityProperty3 { get; set; }
      public string OtherObjectProperty1 { get; set; }
      public string OtherObjectProperty2 { get; set; }
      public string OtherObjectProperty3 { get; set; }
  }
  </code></pre>
  
  <p>In my service class I get an IQueryable of my entities and I send in an argument which contains an enumerable of OtherObject. It works fine when I just want to create DTOs using the Entities properties.</p>
  
  <pre><code>public IEnumerable&lt;DTO&gt; GetDtos(IEnumerable&lt;OtherObject&gt; otherObjects) 
  {
      return _someRepository.GetAll()
          .Where(a =&gt; otherObjects.Select(b =&gt; b.SomeId).Contains(a.SomeId))
          .Select(d =&gt; new DTO()
              {
                  EntityProperty1 = d.EntityProperty1
                  EntityProperty2 = d.EntityProperty2 
                  EntityProperty3 = d.EntityProperty3
              })
          .ToList();
  }
  </code></pre>
  
  <p>However, I would also like to join in some properties from my OtherObject class. If I do the following</p>
  
  <pre><code>public IEnumerable&lt;DTO&gt; GetDtos(IEnumerable&lt;OtherObject&gt; otherObjects) 
  {
      return _someRepository.GetAll()
          .Where(a =&gt; otherObjects.Select(b =&gt; b.SomeId).Contains(a.SomeId))
          .Select(d =&gt; new DTO()
              {
                  EntityProperty1 = d.EntityProperty1
                  EntityProperty2 = d.EntityProperty2 
                  EntityProperty3 = d.EntityProperty3
                  OtherObjectEntity1 = otherObjects.FirstOrDefault(a =&gt; a.SomeId == d.SomeId).OtherObjectEntity1
              })
          .ToList();
  } 
  </code></pre>
  
  <p>I get the following error: "Unable to create a constant value of type XXX. Only primitive types or enumeration types are supported in this context"</p>