I am writing a plugin in CRM 2011. I am trying to use Linq to CRM to retrieve an entity record, here is the code snippet:
Entity legalcase = new Entity("lgl_legalcase");
legalcase = legalDataContext.Lgl_legalcaseSet.FirstOrDefault(l => l.Lgl_legalcaseId == legalCaseGUID);
It is throwing an error on this line saying that it cannot convert from type Microsoft.Xrm.Sdk.Entity to type Legal.Entities.Lgl_legalcase. I have verified that this plugin works fine when using a Retrieve method instead of the LINQ syntax, but I would like to get it working with LINQ. Does anyone know why this is throwing an error?
.ToEntity<Lgl_legalcase>()
at the end and see what happens. In plugins, this is often the solution. I won't go into why this is the case or other strategies for fixing it. - Mike_Matthews_IIvar something = legalDataContext.Lgl_legalcaseSet.FirstOrDefault(l => l.Lgl_legalcaseId == legalCaseGUID)
? It was my assumption this would return aMicrosoft.Xrm.Sdk.Entity
type. - Mike_Matthews_II