简体   繁体   English

使用XRM SDK从ms dynamics crm获取相关数据

[英]get related data from ms dynamics crm using XRM SDK

I'm trying to retrieve data from crm in a .net application, using the SDK. 我正在尝试使用SDK从.net应用程序中的crm检索数据。 I've managed to do simple queries to retrieve lists, but I would now like to get the related entities with items, rather than the ids. 我已经设法做一些简单的查询来检索列表,但是现在我想获取带有项目而不是ID的相关实体。

I have tried things like 我已经尝试过类似的东西

QueryExpression query = new QueryExpression
  {
    EntityName = "opportunity",
....

LinkEntity linkEntityAccount = new LinkEntity()
 {
    LinkFromEntityName = "opportunity",
    LinkFromAttributeName = "opportunityid",
    LinkToEntityName = "serviceappointment",
    LinkToAttributeName = "regardingobjectid",
    JoinOperator = JoinOperator.Inner,
    Columns = new ColumnSet(new string[] { "scheduledstart", "scheduledend" }),
    EntityAlias = "service"
 };

query.LinkEntities.Add(linkEntityAccount);

(This will return a collection of entities from the opportunity table) (这将返回机会表中的实体集合)

However the LinkedEntities just put the two columns in the returns entities. 但是,LinkedEntities只是将两列放在return实体中。

What i would like is (say for this example) is a entity.serviceappointment to be the the entity containing the service appointment entity/data. 我想要的是(例如针对此示例)是一个entity.serviceappointment ,它是包含服务约会实体/数据的实体。 Instead of in entity there being fields such as service.scheduledstart and service.scheduledend 而不是在实体中,存在诸如service.scheduledstartservice.scheduledend字段

I have looked at the Relationship and RelationshipQueryCollection things in the SDK but i have been unable to setup a query that will do the query, without first getting the opportunity entities. 我已经查看了SDK中的RelationshipRelationshipQueryCollection内容,但是在没有先获取opportunity实体的情况下,无法设置将执行该查询的查询。 But it looks like that maybe what I need? 但是看起来好像我需要什么? I'm not sure. 我不确定。

Is this even possible? 这有可能吗? Or should I just continue to query entities individually? 还是应该继续单独查询实体?

Thanks 谢谢

In the QueryExpression the LinkEntity represents a join. QueryExpressionLinkEntity表示一个LinkEntity That's why the fields of the joined table are in the Entity row. 这就是为什么联接表的字段位于“ Entity行中的原因。 They can be distinguished from the 'real' entity attributes by the fact that their names are prefixed (including a dot) and their values are wrapped in an AliasedValue object. 可以通过以下方式将它们与“真实”实体属性区分开:它们的名称带有前缀(包括点),并且其值包装在AliasedValue对象中。

It is possible to unwrap them and create strong typed Entity objects, but you will need to write the code yourself. 可以解开它们并创建强类型的Entity对象,但是您需要自己编写代码。

Alternatively you can consider a few other options: 另外,您可以考虑其他一些选择:

  1. Query for serviceappointment records and join the opportunity records. 查询serviceappointment记录并加入opportunity记录。
  2. Retrieve opportunity records one by one using the RetrieveRequest and include the query for the related service appointments in the request. 检索opportunity记录逐一使用RetrieveRequest ,包括在请求相关服务预约查询。 (See also this discussion on StackOverflow .) (另请参见有关StackOverflow的讨论。)
  3. Create an Action returning all data you need in a convenient OrganizationResponse . 创建一个Action,以方便的OrganizationResponse返回您需要的所有数据。

There's no automatic way to get the entire linked entity data (as an Entity object) that I know of (that's not to say it's impossible, mind you). 没有自动的方法来获取我所知道的整个链接的实体数据(作为Entity对象)(请注意,这并不是说不可能)。

But I think it'd be a lot easier to just query the data you need in another request. 但是我认为仅查询另一个请求中所需的数据会容易得多。

  • Find the list of opportunities you need 查找您需要的机会清单
  • Use the regarding object IDs as the parameter of an "IN" filter for the second query. 使用有关对象ID作为第二个查询的“ IN”过滤器的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM