I'm searching for a method of retrieving the custom entity attribute without generating early bind types with crmsvcutil.

Is there any solution for my problem?

有帮助吗?

解决方案

You don't need to generate early bound types to retrieve entity data from CRM. You can work with a type called Entity (which is similar to the DynamicEntity of CRM4).

The SDK has some examples about how to work with late bound entities here.

This entity class is not strongly typed (unlike early-bound entities generated from crmsvcutil) so you have to perform casts yourself. There is a method on Entity which will help with this. The following code might give you some idea about how to retrieve a late-bound entity.

IOrganizationService service = GetOrganizationService();
var entity = service.Retrieve(entityName,
                                entityId,
                                new ColumnSet(new[]
                                                {
                                                    stringAttributeName,
                                                    intAttributeName,
                                                    floatAttributeName,
                                                    boolAttributeName,
                                                    optionSetAttributeName,
                                                    entityReferenceAttributeName,
                                                }));
var stringValue = entity.GetAttributeValue<string>(stringAttributeName);
var intValue = entity.GetAttributeValue<int?>(intAttributeName);
var floatValue = entity.GetAttributeValue<double?>(floatAttributeName);
var boolValue = entity.GetAttributeValue<bool?>(boolAttributeName);
var optionSetValue = entity.GetAttributeValue<OptionSetValue>(optionSetAttributeName);
var entityReferenceValue = entity.GetAttributeValue<EntityReference>(entityReferenceAttributeName);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top