2013-10-03 61 views
0

我有兩個類例如鏈接多個教學班,短小精悍

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

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

我有查詢設置相匹配的屬性,但我想在我的classses值的值映射。

我如何得到這個工作在短小精悍?

回答

0

您可以使用帶有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(); 
相關問題