Dynamics crm 抓取一个属性';使用过滤器获取XML中的s属性
这是我的FetchXMLDynamics crm 抓取一个属性';使用过滤器获取XML中的s属性,dynamics-crm,fetchxml,Dynamics Crm,Fetchxml,这是我的FetchXML <fetch version="1.0" mapping="logical"> <entity name="cs_testparameter" > <attribute name="cs_testcalculation" /> </entity> </fetch> …但我宁愿不使用数值,而是对名称本身进行筛选。这可能吗 编辑:最后,我将用它来做一些类似于 string fet
<fetch version="1.0" mapping="logical">
<entity name="cs_testparameter" >
<attribute name="cs_testcalculation" />
</entity>
</fetch>
…但我宁愿不使用数值,而是对名称本身进行筛选。这可能吗
编辑:最后,我将用它来做一些类似于
string fetchQuery = @"--my fetchXML here...--";
FetchExpression fetchTestParameters = new FetchExpression(fetchQuery);
EntityCollection testParameters = context.RetrieveMultiple(fetchTestParameters);
foreach (var testParameter in testParameters.Entities)
{
switch (testParameter.cs_testcalculation["name"])
{
case "Addition":
//do something...
case "Subtraction":
//do something else...
...
}
}
我已经找到了一个解决方法:
- 我的FetchXML仍然是一样的
- 我已经使用crmsvcutil生成了选项集的枚举,并将其添加到我的项目中
- 我的
现在看起来像:foreach
询问您最近的编辑: 您只是使用enum使代码更具可读性和可伸缩性,但本质上您是在比较数字。正确答案将是“这是不可能的”,但您处理这一问题的方法是正确的 另一种方法是使用FormattedValues,它允许您询问名称而不是值 后期绑定代码: 或
如何执行fetxml?使用retrievemultiple将始终为您提供结果集合,在该集合中retrieve将返回您真正想要的实体xml实体。我不知道使用optionset名称值获取结果的任何方法,但是,如果您解释了为什么要使用optionset名称值获取结果背后的目的,请说明?任何人都可以建议解决这个问题。@Shane_-Yo我正在使用RetrieveMultiple@AliLee我更新了我的问题,并补充了我最终的目标是什么,这很好。但我只是想知道为什么你不在swtich中使用选项集整数值(硬编码)呢。。。case语句,而不是这个冗长的解决方法?@AliLee对于接管代码的人来说,整数值没有意义。这些值也可能完全改变。如果有更改,最好更新早期绑定类型和选项集类,而不是主代码。我记得(需要确认)如果更改选项集的整数值,实体记录中的现有值将无效。换句话说,这不会是一个级联变化。另一方面,由于拼写错误或名称增强等原因,名称值更容易更改。我个人认为,在代码中使用名称值来执行任务不是一个好方法。
<fetch version="1.0" mapping="logical">
<entity name="cs_testparameter" >
<attribute name="cs_testcalculation" />
<filter type="and">
<condition attribute="cs_testcalculation" operator="eq" value="717640000" />
</filter>
</entity>
</fetch>
string fetchQuery = @"--my fetchXML here...--";
FetchExpression fetchTestParameters = new FetchExpression(fetchQuery);
EntityCollection testParameters = context.RetrieveMultiple(fetchTestParameters);
foreach (var testParameter in testParameters.Entities)
{
switch (testParameter.cs_testcalculation["name"])
{
case "Addition":
//do something...
case "Subtraction":
//do something else...
...
}
}
foreach (var testParameter in testParameters.Entities)
{
switch (((cs_testparameter) testParameter).cs_TestCalculation.Value)
{
case (int)cs_testcalculation.Addition:
//do something...
case (int)cs_testcalculation.Subtraction:
//do something else...
...
}
}
entity.FormattedValues["cs_TestCalculation"]
entity.GetFormattedAttributeValue["cs_TestCalculation"]