Model is as follows,
```
public class CustomersContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
}
public class Customer
{
public Customer()
{
Orders = new List<Order>();
}
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
public class Order
{
public int ID { get; set; }
public int Amount { get; set; }
public Customer Customer { get; set; }
}
```
Query - [http://localhost:8080/odata/Customers?$expand=Orders/Customer](http://localhost:8080/odata/Customers?$expand=Orders/Customer)
Exception:
The type 'System.Web.Http.OData.Query.Expressions.SelectExpandWrapper`1[[SOTests.Customer, SOTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.
Entityframework requires different types for projections involving an entity. For instance, EF fails to translate this query,
```
public class Test
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
}
var query = db.Customers.Select(c => new { Prop1 = new Test { Prop1 = c.ID }, Prop2 = new Test { Prop2 = c.Name } });
```
where as it can translate this query,
```
public class Test<T>
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
}
var query = db.Customers.Select(c => new { Prop1 = new Test<SomeUniqueType1> { Prop1 = c.ID }, Prop2 = new Test<SomeUniqueType2> { Prop2 = c.Name } });
```
```
public class CustomersContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
}
public class Customer
{
public Customer()
{
Orders = new List<Order>();
}
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
public class Order
{
public int ID { get; set; }
public int Amount { get; set; }
public Customer Customer { get; set; }
}
```
Query - [http://localhost:8080/odata/Customers?$expand=Orders/Customer](http://localhost:8080/odata/Customers?$expand=Orders/Customer)
Exception:
The type 'System.Web.Http.OData.Query.Expressions.SelectExpandWrapper`1[[SOTests.Customer, SOTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' appears in two structurally incompatible initializations within a single LINQ to Entities query. A type can be initialized in two places in the same query, but only if the same properties are set in both places and those properties are set in the same order.
Entityframework requires different types for projections involving an entity. For instance, EF fails to translate this query,
```
public class Test
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
}
var query = db.Customers.Select(c => new { Prop1 = new Test { Prop1 = c.ID }, Prop2 = new Test { Prop2 = c.Name } });
```
where as it can translate this query,
```
public class Test<T>
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
}
var query = db.Customers.Select(c => new { Prop1 = new Test<SomeUniqueType1> { Prop1 = c.ID }, Prop2 = new Test<SomeUniqueType2> { Prop2 = c.Name } });
```