order-detail.vala 1.3 KB

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