Sunday 15 July 2012

servicestack - How to set conditions/filters on references when using Load* methods -


I have two tables: the customer and the order customer has a reference to the commands like:

  [context] Public listing & lt; Order & gt; Order Received; Set; }  

The order class has an attribute deleted . I want to load all the clients (or a subset), and include orders, but not with the deleted ones = true. Can this be done with LoadSelect methods, or what is the recommended way?

Something similar that will approximate the following SQL:

  Select * Order customers in C. O.CustomerId = C.Id where O.Deleted = False  

Is this the best way?

  var orderIds = resp.Customers.Select (q = & gt; q.Id) .toList (); Var allOrders = DB Select & lt; Order & gt; (O = & gt; Order EID.Catine (O.CustomerID) & amp; O. O.); Forex Currency (Miscellaneous Orders in All Orders) {var Customer = resp.Customers.First (q = & gt; q.Id == order.custivityId); If (cust.Orders == zero) cust.Orders = new list & lt; Order & gt; (); Cust.Orders.Add (order); }   

I just added a new merge API To include yourself with the child's references in the original collection which will make it a little easier.

With the new API, you can select different customers and commands and merge the collection together, for example:

  // only Select the same customers who have valid orders varian customers = db.Select & lt; Customers & gt; (Q = & gt; q.Join & lt; order & gt; (). Where & lt; order & gt; (o = & gt; o deleted == false). Shortened sign ()); // Order Orders var Orders = DB Select & lt; Order & gt; (O = & gt; o.deleted == incorrect); Customers.Merge (order); // Match results with customers Print dump (); // Print the results of the merged archive  

This change is now available from v4.0.39 + .


No comments:

Post a Comment