I'm having problems saving an entity which I have gotten from CRM using a LINQ query containing a join.
The inner exception I get when trying to update the CRM entity is:
Message = "Message = "'x_productpurchase' entity doesn't contain attribute with Name = 'l_0.statuscode'."
The query:
var subscriptionsTemp = (from p in _serviceContext.x_productpurchaseSet
join l in _serviceContext.x_ProductInOrderSet on p.Id equals l.x_ProductsInOrder.Id
where p.x_contactId.Id == contactID
&& p.x_subscription_type != null
select new { subsciption = p, line = l }).ToList();
List<x_productpurchase> subscriptions = subscriptionsTemp
.Where(x => productTypesToLookFor == null || (x.line.x_productId != null && productTypesToLookFor.Contains(x.line.x_productId.Id)))
.Select(x => x.subsciption).Distinct().ToList<x_productpurchase>();
The purpose of the above code is to retrieve product orders for a certain contact containing specific products defined in List<Guid> productTypesToLookFor.
After we have gotten a row back we change a few values on the retrieved entities and try to save the changes back to CRM using _serviceContext.Update() // XrmServiceContext.
This is when the above error is thrown.
We have come to the conclusion that the error is caused by the Join of a sub table in the query as this seems to introduce an alias in some of the variable names that are returned. This can be seen in the attributes of a retrieved entity (green circles):

Any ideas as to get rid of this problem so we can save and work with the entities right away?
Right now we are solving the problem by doing the above query and then getting the specific product order again using its Guid and then working on that. Not an ideal situation as this forces us to do more database queries.
we change a few valuesdid you change statecode or statuscode fields? - Guido Preite_serviceContext.x_productpurchaseSet[0].Attributesalready contain those that are causing you problems, i.e. thel_0AliasedValues? - p e p