Created
February 24, 2013 21:25
-
-
Save vansha/5025705 to your computer and use it in GitHub Desktop.
Querying complex object hierarchies with dapper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order { | |
public int Id { get; set; } | |
public DateTime OrderedAt { get; set } | |
public IList<OrderLine> OrderLines { get; set } | |
public Person Customer { get; set } | |
} | |
public class OrderLine { | |
public int Id { get; set; } | |
public int Count { get; set; } | |
public int Product { get; set; } | |
public decimal TotalPrice { get; set } | |
} | |
public class Product { | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Description { get; set; } | |
} | |
public class Person { | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
} | |
using (var conn = GetOpenConnection()) | |
{ | |
var query = QueryFor<Order>() | |
.Include(x => x.Customer) | |
.IncludeMany(x => x.OrderLines, opt => opt.Include(x => x.Product)); | |
var sql = @"select * | |
from Order o | |
join Person p on p.Id = o.CustomerId | |
join OrderLines ol on ol.OrderId = o.Id | |
join Product pr on pr.Id = ol.ProductId | |
where o.OrderedAt > @LastCheckedAt") | |
var recentOrders = conn.Query(sql, query, new { LastCheckedAt = DateTime.UtcNow.AddDays(-1) }); | |
} |
Hi! I am also curious about the purpose of QueryFor. Can you give us some update?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Where I find use the method QueryFor ?