Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying child tables with dynamic linq to sql?
    primarykey
    data
    text
    <p>I have a fairly complex query I need to write. I am hoping to do it using Linq to Sql if possible. The database is something like this:</p> <p>Customers(First, Last, ID, Gender) <br> Orders (Date, Quantity, Weight, ItemName, Price) <br> Address (City, State, Zip)</p> <p>The query would be to let a user search by any of these fields, and in the case of the number fields, to search &lt;, =, or > as they desire.</p> <p>Something like this would be sample query that I'm required to implement:</p> <p>Query 1: Select customers where first name = 'John' and have at least one order with (Weight > 40 OR Quantity > 10 OR Price > 5) and zipcode = 12345.</p> <p>Query 2: Select customers where first name = 'John' and have at least one order with Weight &lt; 20 and ItemName = 'widget' and Quantity = 10) and zipcode = 12345.</p> <p>I can get the basic part of searching for customers, but I am stuck on searching the Order table where the user can specify &lt;>= in an OR manner.</p> <p><pre><code></p> <pre><code>query = Context.Customers.AsQueryable(); if (searchingFirstName) query = query.Where(cust =&gt; cust.First == firstName); if (searchingLastName) query = query.Where(cust =&gt; cust.Last == lastName); if (searchingZip) query = query.Where(cust =&gt; cust.Address.Zip == zip); // using dynamic Linq if (searchingGender) query = query.Where("Gender == @0", gender); // how do I search the Orders? The dynamic linq functions appear // to only work on the top level table </code></pre> <p></pre></code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload