order-detail.vala 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using InvercargillSql.Orm;
  2. using InvercargillSql.Orm.Projections;
  3. /**
  4. * Join projection demonstrating entity relationships across User, Order, and Product.
  5. */
  6. public class OrderDetail : Object {
  7. public int64 order_id { get; set; }
  8. public string user_name { get; set; }
  9. public string product_name { get; set; }
  10. public int64 quantity { get; set; }
  11. public double total { get; set; }
  12. public string status { get; set; }
  13. public OrderDetail() {
  14. user_name = "";
  15. product_name = "";
  16. status = "";
  17. }
  18. public static void configure_projection(ProjectionBuilder<OrderDetail> p) throws ProjectionError {
  19. p.source<User>("u")
  20. .join<Order>("o", "u.id == o.user_id")
  21. .join<Product>("p", "o.product_id == p.id")
  22. .select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
  23. .select<string>("user_name", "u.name", (x, v) => x.user_name = v)
  24. .select<string>("product_name", "p.name", (x, v) => x.product_name = v)
  25. .select<int64?>("quantity", "o.quantity", (x, v) => x.quantity = v)
  26. .select<double?>("total", "o.total", (x, v) => x.total = v)
  27. .select<string>("status", "o.status", (x, v) => x.status = v);
  28. }
  29. }