Note that there are some explanatory texts on larger screens.

plurals
  1. POI get a null value for a non-nullable foreign key with the entity framework
    primarykey
    data
    text
    <p>What am I doing wrong? I mapped a SQL server database with the wizard. It's a rather complex database, but for this example we can assume three tables: REPORTROWS, REPORTCOLUMNS and REPORTNAMES. REPORTROWS has the following columns ID, RESULT, REPORTDATE, REPORTCOLUMNID, REPORTNAMEID. REPORTNAMES and REPORTCOLUMNS are very simple tables with ID, NAME. ID are always primary keys and REPORTCOLUMNSID and REPORTNAMESID are the foreign keys that link REPORTROWS with REPORTCOLUMNS and REPORTNAMES.</p> <p>Now I populate the three tables with valid values (I do not violate any foreign key constraints). When I call the following code</p> <pre><code>var recs = from a in ctx.REPORTROWS where a.REPORTNAMES.NAME == "my report" &amp;&amp; a.REPORTDATE == somedate select a; </code></pre> <p>I get the rows I want, but I cannot use the field a.REPORTCOLUMNS later in the code because it is null!! Why? REPORTCOLUMNID is defined as a non-nullable integer (that's why it's the foreign key). However, the field a.REPORTNAMES is correct. a.REPORTDATE remains null even if I add <code>&amp;&amp; a.REPORTCOLUMNS != null</code> to the query.</p> <p>I've seen links with similar questions but I couldn't find a definitive answer. Can anybody please help me. For your information, I am using .NET Framework 3.5 and I coulnd't check the "include foreign keys" in the wizard while mapping the database. It was grayed out (and I still don't understand why).</p> <p>Thanks a lot in advance</p> <p>It's the EF version v2.0.50727</p>
    singulars
    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.
 

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