要检查的第一件事是,你的自定义实体在自定义实体屏幕启用重复检测。如果没有,请打开它并发布实体,然后从SDK中转到此代码。此代码将根据帐户名称搜索重复帐户。
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the account instance and set the name property.
account acct = new account();
acct.name = "Microsoft";
// Create the request object.
RetrieveDuplicatesRequest Request = new RetrieveDuplicatesRequest();
Request.BusinessEntity = acct;
Request.MatchingEntityName = EntityName.account.ToString();
Request.PagingInfo = new PagingInfo();
// Execute the request.
RetrieveDuplicatesResponse Response =
(RetrieveDuplicatesResponse) Service.Execute(Request);
如果你想用一个动态的实体与上面的代码,只是实例化一个动态的实体,而不是使一个帐户的线路,并设置“ReturnDynamicEntities”真Request对象上。如果你正在寻找一种方式来开始搜索整个数据库的副本,而不是询问特定的记录是重复的,这里是代码:
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create a query expression for the bulk duplicate detection.
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.account.ToString();
// Create the request (do not send an e-mail).
BulkDetectDuplicatesRequest request = new BulkDetectDuplicatesRequest();
request.JobName = "Detect Duplicate Accounts";
request.Query = query;
request.RecurrencePattern = string.Empty;
request.RecurrenceStartTime = new CrmDateTime();
request.RecurrenceStartTime.Value = DateTime.Now.ToString("s");
request.SendEmailNotification = false;
request.ToRecipients = new Guid[0];
request.CCRecipients = new Guid[0];
request.TemplateId = Guid.Empty;
// Execute the request.
BulkDetectDuplicatesResponse response = (BulkDetectDuplicatesResponse)service.Execute( request);
Guid jobId = response.JobId;
这是使用BulkDetectDyplicates消息。这应该让你走上正确的道路。
您是否必须使用动态实体?如果您引用其类,则您的自定义实体仍为业务实体... – devin