开发者

Crm 2011 get custom entity record attribute without early bound types

开发者 https://www.devze.com 2023-04-03 23:07 出处:网络
I\'m searching for a method of retr开发者_如何学Cieving the custom entity attribute without generating early bind types with crmsvcutil.

I'm searching for a method of retr开发者_如何学Cieving 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号