Dapper and anonymous Types

前端 未结 3 1814
刺人心
刺人心 2020-12-08 07:38

Is it possible to use anonymous types with Dapper?

I can see how you can use dynamic i.e.

connection.Query(blah, blah, blah) 
         


        
3条回答
  •  情书的邮戳
    2020-12-08 07:54

    Is it possible to use anonymous types with Dapper?

    Sure see the non-generic Query override, it return a dynamic IDictionary this object is an expando that can either be cast or accessed with dot notation.

    Eg:

    var v = connection.Query("select 1 as a, 2 as b").First(); 
    Console.Write("{0} {1}",v.a, v.b) // prints: 1 2
    

    is it then possible to do a .Select

    Sure, you get an IEnumerable ... you can run anything you want on that.

提交回复
热议问题