将EntityReference转换为Entity [英] Convert EntityReference to Entity

查看:340
本文介绍了将EntityReference转换为Entity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将EntityReference转换为Entity。

Does anyone know how can Convert EntityReference to Entity.

protected override void Execute(CodeActivityContext executionContext)
{
    [Input("Email")]
    [ReferenceTarget("email")]
    public InArgument<Entity> EMail { get; set; }


    Entity MyEmail = EMail.Get<Entity>(executionContext);

这给我一个错误。无法转换。

This give me an error. Cannot convert this.

推荐答案

问题的最简单答案是查询数据库,以查询由实体引用指出(引用)的实体。我一直将实体引用视为(大致)等同于C ++中的指针。它有地址(引导),但是您需要取消引用它才能进入蜂蜜。

The shortest answer to your questions is to query the database for the entity that's pointed out (referred to) by the entity reference. I've always viewed entity references as (rough) equivalent to the pointers in C++. It's got the address to it (guid) but you need to de-reference it in order to get to the honey. You do that like this.

IOrganizationService organization = ...;
EntityReference reference = ...;

Entity entity = organization.Retrieve(reference.LogicalName, reference.Id, 
  new ColumnSet("field_1", "field_2", ..., "field_z"));

当我做了很多从 EntityReference Entity的转换时,我为字段部署了带有可选参数的扩展方法。

When I do a lot of converting from EntityReference to Entity, I deploy the extension method with optional parameter for the fields.

public static Entity ActualEntity(this EntityReference reference,
  IOrganizationService organization, String[] fields = null)
{
  if (fields == null)
    return organization.Retrieve(reference.LogicalName, reference.Id, 
      new ColumnSet(true));
  return organization.Retrieve(reference.LogicalName, reference.Id, 
    new ColumnSet(fields));
}

您可以阅读更多内容并进行比较 EntityReference 实体

You can read more and compare EntityReference and Entity.

这篇关于将EntityReference转换为Entity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆