我现在使用CrmScUtil创建CrmProxy类,当我尝试使用它时,我遇到了一些问题。
创建联系人工作正常,但更新和删除只会抛出此错误:
{“处理此请求时出错。”}
at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options) 在Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges()
你能否让我知道我做错了什么?,查询工作时会返回我想要更新/删除的联系人数据。
OrganizationServiceProxy orgserv; orgserv = new OrganizationServiceProxy(orgConfigInfo,clientCreds); orgserv.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
//Create
using (var context = new XrmContext(orgserv))
{
Contact contact = new Contact()
{
FirstName = "fName",
LastName = "lName",
Address1_Line1 = "Address1_Line1",
Address1_City = "Address1_City",
Address1_StateOrProvince = "XX",
Address1_PostalCode = "00000",
Telephone1 = "(000) 000-0000",
JobTitle = "JobTitle",
Company = "Company",
EMailAddress1 = "test@test.com"
};
context.AddObject(contact);
context.SaveChanges();
}
//End Create
//Update
using (var contextUpdate = new XrmContext(orgserv))
{
try
{
Contact con = contextUpdate.ContactSet.FirstOrDefault(c => c.EMailAddress1 == "test@test.com");
if (con != null)
{
con.Fax = "Fax132456";
contextUpdate.UpdateObject(con);
contextUpdate.SaveChanges();
}
}
catch (Exception ex)
{
}
}
//End Update
//Delete
using (var contextDelete = new XrmContext(orgserv))
{
Contact con = contextDelete.ContactSet.FirstOrDefault(c => c.EMailAddress1 == "test@test.com");
if (con != null)
{
contextDelete.DeleteObject(con);
contextDelete.SaveChanges();
}
}
//End Delete
答案 0 :(得分:1)
我能够找到答案,我希望这会有所帮助:
最新的CoreAssamblies(7.1.0)
似乎存在错误所以关键是卸载NuGet包并安装7.0.0
安装包Microsoft.CrmSdk.CoreAssemblies -Version 7.0.0
之后没有任何问题。