在 MS CRM 4.0 中创建动态实体
我正在尝试使用动态实体创建新联系人。 我在 CRM SDK 中找到的示例有此代码。
// Set the properties of the contact using property objects.
StringProperty firstname = new StringProperty();
firstname.Name = "firstname";
firstname.Value = "Jesper";
StringProperty lastname = new StringProperty();
lastname.Name = "lastname";
lastname.Value = "Aaberg";
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {firstname, lastname};
在我的代码中,我有以下实现。
StringProperty sp_Field1 = new StringProperty("Field1","Value1");
StringProperty sp_Field2 = new StringProperty("Field2","Value1");
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {sp_Field1,sp_Field2};
我没有看到代码有太大差异。 在我在互联网上找到的示例中,我具有与在 SDK 中找到的相同的实现。 但如果我运行相同的代码,我会收到以下错误
CS0029:无法将类型“Microsoft.Crm.Sdk.StringProperty”隐式转换为“Microsoft.Crm.Sdk.PropertyCollection”
我尝试创建一个 PropertyCollection 类型的新变量(属于 mscrm 命名空间)并将 stringproperty 添加到其中并通过它到实体。
Microsoft.Crm.Sdk.PropertyCollection propTest = new Microsoft.Crm.Sdk.PropertyCollection();
propTest.Add(sp_SSNNo);
propTest.Add(sp_FirstName);
contactEntity.Properties = new Property[] {propTest};
这给了我以下错误
CS0029:无法将类型“Microsoft.Crm.Sdk.PropertyCollection”隐式转换为“Microsoft.Crm.Sdk.Property”
我确信它是一个较小的类型转换错误,但我无法弄清楚错误在哪里。 此外,即使这是一个类型转换错误,为什么它适用于互联网上给出的所有示例,而不适用于我。 我尝试运行代码示例,但遇到了相同的转换错误。 如果您需要更多这方面的信息,请告诉我,任何有关这方面的帮助将不胜感激。
I am trying to create a new contact using Dynamic Entity. The sample i found in CRM SDK had this code.
// Set the properties of the contact using property objects.
StringProperty firstname = new StringProperty();
firstname.Name = "firstname";
firstname.Value = "Jesper";
StringProperty lastname = new StringProperty();
lastname.Name = "lastname";
lastname.Value = "Aaberg";
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {firstname, lastname};
In my code i have the following implementation.
StringProperty sp_Field1 = new StringProperty("Field1","Value1");
StringProperty sp_Field2 = new StringProperty("Field2","Value1");
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {sp_Field1,sp_Field2};
I don't see much differences in the code. In the examples i found in the internet i have the same implementation as i found in SDK. But if i run the same i get the following error
CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.StringProperty' to 'Microsoft.Crm.Sdk.PropertyCollection'
I tried created a new variable of type PropertyCollection(one that belongs in mscrm namespace) and added the stringpropertys into that and passed it to the entity.
Microsoft.Crm.Sdk.PropertyCollection propTest = new Microsoft.Crm.Sdk.PropertyCollection();
propTest.Add(sp_SSNNo);
propTest.Add(sp_FirstName);
contactEntity.Properties = new Property[] {propTest};
This gave me the following error
CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.PropertyCollection' to 'Microsoft.Crm.Sdk.Property'
I am sure its a minor typecasting error but i am not able to figure out where the error is. And moreover, even if it was a typecasting error why is it working for all the samples given in the internet and not for me. I tried getting the code sample to run but i am encountering the same conversion error. Please let me know if you need more info on this, any help on this would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是 Microsoft 的一篇文章,试图讨论此主题:
http://community.dynamics.com/blogs/cscrmblog/archive/2008/06/23/web -services-amp-dlls-or-what-s-up-with-all-the-duplicate-classes.aspx
这不是您遇到的错误,而是两种方式之间的设计差异这两个组件的工作原理以及它们的设计目的。
如果您想继续使用 Microsoft.Crm.Sdk.dll,您应该能够通过以下方式实现您的目标...
Here is an article from Microsoft that makes an attempt to discuss this topic:
http://community.dynamics.com/blogs/cscrmblog/archive/2008/06/23/web-services-amp-dlls-or-what-s-up-with-all-the-duplicate-classes.aspx
This is not a bug that you are running into but more of a difference in design between the way the two assemblies work and what they are designed to do.
If you want to continue to use the Microsoft.Crm.Sdk.dll you should be able to accomplish your goal with the following...
感谢 SaaS 开发人员,该代码现在运行良好。 另一种方法是将 StringProperty 直接添加到实体属性集合中。
再次感谢您的回复:)
Thanks SaaS Developer, that code is working fine now. One more way of doing it would be to directly add the StringProperty to the entity property collection.
Thanks again for replying :)
我相信问题在于您正在引用 Microsoft.Crm.Sdk 程序集中的动态实体类。 SDK 中的示例使用对 CRM Web 服务的引用。 这可能会令人困惑,因为两个程序集都包含许多相同的类型,但它们是不同的。
I believe the issue is that you are referencing the dynamic entity class in the Microsoft.Crm.Sdk assembly. The sample in the SDK is using a reference to the CRM web service. This can get confusing as both assemblies contain many of the same types, however they are different.