Luk*_*lch 5 c# linq early-binding dynamics-crm-2011
我一直在转换我的一些CRM4.0插件来使用CRM2011 SDK.我刚刚开始使用LINQ for Early-Bound实体并遇到了一个问题.
我试图在连接的实体中获取OptionSetValue的格式化值.在查看此MSDN SDK查询示例后,我设法检索主要实体的格式化值,但似乎无法将其转换为已连接的实体.
下面的代码是我正在尝试实现的示例.我开始使用SDK示例中的代码.
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();
Run Code Online (Sandbox Code Playgroud)
account_formattedValues和account_addresstypename遇到纠正,我可以访问该数据,但由于某种原因,contact_formattedValues项包含一个空集合,因此contact_addresstypename为null.
我这样做不正确,还是我错过了什么?有没有人能够或知道如何实现这一目标?任何帮助是极大的赞赏.
LINQ查询提供程序中存在一个错误,其中格式化的值未正确应用于第一个实体后面的实体.它与QueryExpression API(LINQ提供程序使用)如何处理连接查询有关.它通过汇集第一个/主要实体(技术上唯一的实体)中的所有属性和格式化值来实现.然后,它使用一组" 链接别名 "来对这些值进行分类.我们可以利用它作为缺少的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);
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,所有值从"一"参数拉标签,最棘手的部分是要知道别名/前缀值是(对于非主实体),这是基于实体设置参数的名称动态创建的字符串是什么,"c"和计数器值.这可以通过转储主实体的FormattedValues来检查.
归档时间: |
|
查看次数: |
4128 次 |
最近记录: |