我想使用dapper从数据库中查询复杂的实体。
实施例。 Job是我想要查询的顶级实体。
public class Job
{
public User User { get; set; }
}
public class Account
{
}
public class Roles
{
public IList<Schedule> Schedules { get; set; }
}
public class Devices
{
public IList<Roles> Roles { get; set; }
public IList<Account> Accounts { get; set; }
}
public class Schedule
{
}
public class User
{
public IList<Account> Accounts { get; set; }
public Profile Profile { get; set; }
}
public class Profile
{
public IList<Account> Accounts { get; set; }
}
这是否可能与小巧玲珑,如果它是值得使用dapper为此或我应该使用其他ORM(EF,LLBLGen,NH)?
答案 0 :(得分:0)
我相信你问的是如何在Dapper中实现MultiMapping。
您可以传递多个模型:
var sql = @"select * from Product p
inner join Customer c on p.CustomerId = c.CustomerId
order by p.ProductName";
var item = connection.Query<ProductItem, Customer, ProductItem>(sql,
(p, c) => { p.Customer = c; return p; }, splitOn: "CustomerId").First();