我注意到了CRM主持人大卫Jennaway在TechNet论坛指出,你不能使用LINQ更新/ 2011年CRM创建的记录在这里看到http://social.microsoft.com/Forums/en-IE/crmdevelopment/thread/682a7be2-1c07-497e-8f58-cea55c298062LINQ CRM 2011更新 - 创建
但我已经看到了一些线程,使它看起来好像它应该工作。这是我的尝试,不起作用。任何想法为什么不呢?
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
EntityState state = new EntityState();
state = EntityState.Changed;
var counter = from c in orgContext.CreateQuery<pcx_entitycounter>()
where c.pcx_name.Contains("pcx_candidate")
select new pcx_entitycounter
{Id = c.Id,
pcx_name = c.pcx_name, pcx_Sequence = c.pcx_Sequence, pcx_Prefix = c.pcx_Prefix
};
foreach (var c in counter)
{
string prefix = c.pcx_Prefix.ToString(); ;
string sequence = c.pcx_Sequence.ToString();
c.pcx_Sequence = c.pcx_Sequence + 1;
c.EntityState = state;
**service.Update(c);** //FAILS HERE
}
此LINQ如何进行更新?我看到你正在运行一个LINQ查询,但没有在实际的更新?你有什么异常? – 2011-05-26 21:09:02
当然会有助于查看例外情况以及所有相关细节。 – cchamberlain 2011-06-05 16:15:58