I would like to know how I can set the EntityCollection in the Linq Projection. Below is my code:
var orders = (from order in context.Orders
select new
{
reference = order.reference,
pe = order.OrderExecutions
})
.AsEnumerable()
.Select(o =>
(Orders)new Orders
{
reference = o.reference,
OrderExecutions = o.pe
}
).ToList().AsQueryable();
(This code seems weird, but it must be such as to work in the telerik grid)
The manual OrderExecutions = o.peincludes this error:
EntityCollection has already been initialized. The InitializeRelatedCollection method should be called only to initialize a new EntityCollection during deserialization of the object graph.
OrderExecutions is the EntityCollection contained in the Orders object.
How can I avoid this error? Any idea?
Should I change the generated code in the Order object?
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("PModel", "FK__orderExec__refer__70DDC3D8", "OrderExecutions")]
public EntityCollection<OrderExecutions> OrderExecutions
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<OrderExecutions>("PModel.FK__orderExec__refer__70DDC3D8", "OrderExecutions");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<OrderExecutions>("PModel.FK__orderExec__refer__70DDC3D8", "OrderExecutions", value);
}
}
}
Thanks in advance.
source
share