Note that there are some explanatory texts on larger screens.

plurals
  1. PODon't know how to generate the query I need using Entity Framework 4
    text
    copied!<p>I've got an Entity Framework 4 model. There's 2 tables in that model, Subscribers and Versions:</p> <pre><code>CREATE TABLE tracking."Subscribers" ( "SubscriberId" UUID NOT NULL, "RemoteAddress" VARCHAR(80) NOT NULL, "Priority" INTEGER NOT NULL DEFAULT 100, "DataTypeId" INTEGER NOT NULL REFERENCES tracking."DataTypes" ( "DataTypeId" ), "Condition" VARCHAR(8000), "Version" BIGINT NOT NULL DEFAULT 0, "LastConnected" TIMESTAMPTZ NOT NULL, CONSTRAINT "Subscribers_pkey" PRIMARY KEY ("SubscriberId", "DataTypeId") ); CREATE TABLE tracking."Versions" ( "ObjectId" UUID NOT NULL, "Source" UUID NULL, "From" BIGINT NOT NULL, "To" BIGINT NULL, "DataTypeId" INTEGER NOT NULL REFERENCES tracking."DataTypes" ( "DataTypeId" ), CONSTRAINT "Versions_pkey" PRIMARY KEY ("ObjectId", "DataTypeId") ); </code></pre> <p>Yes, there is a third table, DataTypes, but it's a lookup table &amp; isn't important.</p> <p>Also, you need to know that the values stored in the From &amp; To columns in the Versions table represent version numbers. If the To column is not null, it means that the particular item represented by ObjectId has been deleted from the database.</p> <p>In my C# code, I need to build a query. There is a Dictionary which contains one entry for each combination of data type ID &amp; version number. I need to build a series of tests spearated by ORs, not ANDs.</p> <p>Normally, to build the condition as a string for use in a DbCommand, I'd use code like this:</p> <pre><code>bool isFirst = true; string query = "..."; foreach ( KeyValuePair&lt;int, long&gt; version in versionsLastSent ) { if ( ! isFirst ) { query += " OR "; } query += "...."; isFirst = false; } </code></pre> <p>However, I don't know how to get that OR into the query using entity framework. I know that my query will be a generic IQueryable object and that I add conditions to it using</p> <pre><code>query = query.Where( a =&gt; ... ); </code></pre> <p>But these are normally separated by ANDs. I need ORs.</p> <p>How do I do this?</p> <p>Tony</p> <p>Edit:</p> <p>I forgot to mention that the query needs to look like this when done:</p> <p>SELECT * FROM Versions JOIN Subscribers . . . WHERE &lt;Some Condition&gt; AND ( VersionCondition1 OR VersionCondition2 OR . . . )</p>
 

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