【发布时间】:2015-08-06 03:50:51
【问题描述】:
我现在使用 CrmScUtil 创建 CrmProxy 类,当我尝试使用它时遇到了一些问题。
创建联系人可以正常工作,但更新和删除只会引发此错误:
{“处理此请求时发生错误。”}
在 Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions 选项) 在 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
【问题讨论】: