1

例如,我有两节课

class User
{
  string name {get;set;}
  int age {get;set;} 
  Register reg {get;set;}
}

class Register 
{
 datetime time {get; set;}
 bool active {get;set;}
}

我设置了查询以匹配属性,但我想将值映射到我的类中的值。

我怎样才能让它在小巧玲珑的环境中工作?

4

1 回答 1

1

您可以使用带有 spliton 参数的多图查询。比较http://www.tritac.com/bp-24-dapper-net-by-example

public class Account {
  public int? Id {get;set;}
  public string Name {get;set;}
  public string Address {get;set;}
  public string Country {get;set;}
  public int ShopId {get; set;}
  public Shop Shop {get;set;}
}
public class Shop {
  public int? ShopId {get;set;}
  public string Name {get;set;}
  public string Url {get;set;}
}

var resultList = conn.Query<Account, Shop, Account>(@"
                SELECT a.Name, a.Address, a.Country, a.ShopId
                        s.ShopId, s.Name, s.Url
                FROM Account a
                INNER JOIN Shop s ON s.ShopId = a.ShopId                    
                ", (a, s) => {
                     a.Shop = s;
                     return a;
                 },
                 splitOn: "ShopId"
                 ).AsQueryable();
于 2013-10-08T11:38:28.090 回答