Call custom constructor with Dapper?

前端 未结 2 591
失恋的感觉
失恋的感觉 2020-12-29 06:26

I\'m trying to use Dapper to interface with the ASP.NET SQL Membership Provider tables. I wrapped the SqlMembershipProvider class and added an additional method to get me t

相关标签:
2条回答
  • 2020-12-29 06:43

    I use this maybe it's help someone

    YourList = connection.Query<YourQueryClass>(Query, arg)
                  .Select(f => new ClassWithConstructor(f.foo,f.bar))
                  .ToList();  
    
    0 讨论(0)
  • 2020-12-29 06:59

    I would use the non-generic Query API here...

     return connection.Query(sql, args).Select(row =>
         new AnyType((string)row.Foo, (int)row.Bar) {
             Other = (float)row.Other }).ToList();
    

    Using this you can use both non-default constructors and property assignments, without any changes, by using "dynamic" as an intermediate step.

    0 讨论(0)
提交回复
热议问题