Dynamics CRM Plugin FetchXML link-entity 查詢

link-entity中的Attribute查詢需要注意兩點:

1 在Attribute的name前,需要加上link-entity的alias的name。

2 在獲取Attribute的值時,需要用AliasedValue強制轉換。

demo

string fetchQuery = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                            <entity name='new_priceevaluationdetail'> 
                                <attribute name='new_priceevaluationdetailid' />
                                <filter type='and'>
                                    <condition attribute='statecode' operator='eq' value='0' />
                                </filter>
                                <link-entity name='new_partinfo' from='new_partinfoid' to='new_partinfoid' alias='bb'>
                                    <attribute name='new_dressingrate' />
                                    <attribute name='new_singledosage' />
                                    <attribute name='new_price' />
                                </link-entity>                                                        
                            </entity>
                        </fetch>";
    FetchExpression fetchExp = new FetchExpression(fetchQuery);
    EntityCollection result = plugin.SysService.RetrieveMultiple(fetchExp);
    if (result.Entities.Count > 0)
    {
        foreach (Entity ent_quotationParts in result.Entities)
        {
                                          
            decimal singledosage = ent_quotationParts.Contains("bb.new_singledosage") ? (decimal)((AliasedValue)(ent_quotationParts["bb.new_singledosage"])).Value : 0;
                                       
            decimal dressingrate = ent_quotationParts.Contains("bb.new_dressingrate") ? decimal.Parse(((AliasedValue)ent_quotationParts["bb.new_dressingrate"]).Value.ToString())/100 : 0;
                                         
            decimal price = ent_quotationParts.Contains("bb.new_price") ? ((Money)((AliasedValue)(ent_quotationParts["bb.new_price"])).Value).Value : 0;
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章