QueryExpression vs. FetchXml CRM2011

前端 未结 4 770
太阳男子
太阳男子 2020-12-30 14:47

We found out that Linq for CRM 2011 is horribly broken - it seems to have gotten in without any QA performed on it. An indicator as how badly broken the provider is a query

4条回答
  •  囚心锁ツ
    2020-12-30 15:32

    I've been asked specifically by a client to use the Query Expression model, so in order to make my life easier, I've resorted to adding a lot of extension methods to IOrganizationService. Examples Include:

    public static List GetEntities(
        this IOrganizationService service, 
        params object[] columnNameAndValuePairs
    ) where T : Entity
    

    which converts the params object[] and T entity type into a query expression, and automatically returns the results to an entity list. So it is used like so:

    foreach(var c in service.GetEntities("lastname", "Doe", "firstname", "Smith"))
    {
        ... 
    }
    

    I also use this one a lot too:

    public static T GetFirstOrDefault(
        this IOrganizationService service,
        params object[] columnNameAndValuePairs
    ) where T : Entity
    
    var c = service.GetFirstOrDefault("owner", id);
    

    These type of extension methods make working with query expressions a lot easier, giving you a much more LINQ type style, without weird linq restriction traps that are easy to fall into.

提交回复
热议问题