I'm attempting to understand some of the differences between Dynamics LINQ and Entity Framework LINQ. I've generated the strongly typed classes and a context using the CrmSvcUtil.exe utility. This sample code throws the following exception:
using System.Configuration; using System.Linq; using CrmEntities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Tooling.Connector; namespace ConsoleConnectToCrm { public static class CrmLinqTest { private static readonly string _connectionStringName = "PORTR2015"; private static IOrganizationService _orgService; public static void Run() { var crmServiceClient = new CrmServiceClient(ConfigurationManager.ConnectionStrings[_connectionStringName].ConnectionString); _orgService = (IOrganizationService)crmServiceClient.OrganizationWebProxyClient != null ? (IOrganizationService)crmServiceClient.OrganizationWebProxyClient : (IOrganizationService)crmServiceClient.OrganizationServiceProxy; var crmCtx = new CrmEntities.CrmLinqContext(_orgService); //Add a new account var newAccount = new Account() { Name = "Linq Coffee Shop", NumberOfEmployees = 12, AccountCategoryCode = new OptionSetValue(1), CreditLimit = new Money(12000) }; crmCtx.AddObject(newAccount); var saveResults = crmCtx.SaveChanges(); //Retrieve the newly added account var retAccount = crmCtx.AccountSet.FirstOrDefault(x => x.Id == newAccount.Id); retAccount.CreditLimit = new Money(15000); //Update the changes back to the context crmCtx.UpdateObject(retAccount); saveResults = crmCtx.SaveChanges(); } } }
This exception is thrown when the final SaveChanges() tries to run.
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/.../Services:request. The InnerException message was 'Error in line 1 position 13160. Element 'schemas.datacontract.org/.../System.Collections.Generic:value' contains data from a type that maps to the name 'schemas.microsoft.com/.../Contracts:ConcurrencyBehavior'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'ConcurrencyBehavior' and namespace 'schemas.microsoft.com/.../Contracts'.'. Please see InnerException for more details."