CRM 2011 - 从加盟实体检索FormattedValues [英] CRM 2011 - Retrieving FormattedValues from joined entity

查看:150
本文介绍了CRM 2011 - 从加盟实体检索FormattedValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把一些我的CRM4.0的插件使用CRM2011的SDK。我刚开始使用LINQ工作的早期绑定实体和所遇到的问题。

I've been converting some of my CRM4.0 plugins to use the CRM2011 SDK. I'm just starting to work with LINQ for Early-Bound entities and have come across a problem.

我想获得一个参加实体的OptionSetValue的格式化值。看着这个MSDN SDK查询示例后,我设法以检索格式化的值主要实体,但似乎无法翻译的一个加盟实体。

I am trying to get the formatted value of an OptionSetValue in a joined entity. After looking at this MSDN SDK Query Example, I managed to retrieve the formatted values for the primary entity, but can't seem to translate that to a joined entity.

下面的代码是什么,我试图实现一个样本。我开始使用从SDK的例子的代码。

The code below is a sample of what I'm trying to achieve. I started by using the code from the SDK example.

var query_join8 = (from a in sContext.AccountSet
                    join c in sContext.ContactSet
                        on a.PrimaryContactId.Id equals c.ContactId
                        into gr
                    from c_joined in gr.DefaultIfEmpty()
                    select new
                                {
                                    contact_name = c_joined.FullName,
                                    account_name = a.Name,
                                    account_addresstypecode = a.Address1_AddressTypeCode,
                                    account_addresstypename = a.FormattedValues.ContainsKey("address1_addresstypecode") ? a.FormattedValues["address1_addresstypecode"] : null,
                                    account_formattedValues = a.FormattedValues,
                                    contact_addresstypecode = c_joined.Address1_AddressTypeCode,
                                    contact_addresstypename = c_joined.FormattedValues.ContainsKey("address1_addresstypecode") ? c_joined.FormattedValues["address1_addresstypecode"] : null,
                                    contact_formattedValues = c_joined.FormattedValues,
                                }).ToArray();



account_formattedValues和account_addresstypename遇到纠正,我有机会获得这些数据,但由于某些原因,contact_formattedValues项目包含一个空的集合,从而contact_addresstypename为null。

The account_formattedValues and account_addresstypename come across corrected and I have access to that data, but for some reason the contact_formattedValues item contains an empty collection, and thus contact_addresstypename is null.

我是不是正确这样做,或者我错过了什么?有没有人能够或者知道如何实现这一目标?任何帮助是极大的赞赏。

Am I doing this incorrectly, or have I missed something? Has anyone been able or knows how to achieve this? Any help is greatly appreciated.

推荐答案

有在LINQ查询提供一个臭虫,格式化的值不正确地应用到第一实体下列实体。这是关系到QueryExpression API(其中LINQ提供程序)如何处理连接查询。它通过集中所有的属性和格式的值在第一个/主实体(技术上的唯一实体)这样做。然后,它使用了一套链接的别名进行分类这些值。我们可以利用这作为一种变通方法缺少FormattedValues。

There is a bug in the LINQ query provider where the formatted values are not properly applied to the entities following the first entity. It is related to how the QueryExpression API (which the LINQ provider uses) handles join queries. It does so by pooling all the attributes and formatted values in the first/primary entity (technically the only entity). It then uses a set of "link aliases" to categorize these values. We can exploit this as a workaround to the missing FormattedValues.

var acs =
    from a in context.AccountSet
    join c in context.ContactSet on a.PrimaryContactId.Id equals c.ContactId
    into gr
    from c_joined in gr.DefaultIfEmpty()
    select new
    {
        account_addresstypecode = a.Address1_AddressTypeCode,
        account_addresstypename = a.FormattedValues["address1_addresstypecode"],
        contact_addresstypecode = c_joined.Address1_AddressTypeCode,
        contact_addresstypename = a.FormattedValues["c_0.address1_addresstypecode"],
        a.FormattedValues
    };

foreach (var ac in acs)
{
    foreach (var pair in ac.FormattedValues)
    {
        Console.WriteLine("{0} {1}", pair.Key, pair.Value);
    }
}



注意所有的标签值是从一拉参数,棘手的部分是知道的别名/前缀值是什么(用于非主实体),它是基于该实体设置参数,名称的动态创建的串c和一个计数器值。这可以通过反倾销的主要实体的FormattedValues进行检查。

Notice all the label values are pulled from the "a" parameter, The tricky part is knowing what the alias/prefix value is (for the non-primary entities) which is a dynamically created string based on the name of the entity-set parameter, "c", and a counter value. This can be inspected by dumping the FormattedValues of the primary entity.

这篇关于CRM 2011 - 从加盟实体检索FormattedValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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