Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Identity Maps</strong></p> <p>A common problem when using ORMs (ok, maybe not exactly common, but it can happen) is that a query which you expect to return distinct records ends up returning multiple copies of the same record. This is often caused by the ORM's Identity Map. Here's a quick overview of how it normally works.</p> <p>The identity map is essentially an object cache, based on the primary key of each object. </p> <p>When you ask the ORM for a record with a certain primary key, it'll check to see if the record already exists in the identity map. If it does already exist, it'll return the existing record.</p> <p>This is usually pretty handy, but sometimes things go wrong. If two objects have the same primary key, or if you haven't specified what the primary keys are (forcing the ORM to guess), the identity map can't distinguish between them, and the first one will always be returned.</p> <p>The moral of the story is, always double-check your primary keys if you are seeing multiple copies of the same record where you shouldn't be!</p> <hr> <p>In this question, the code</p> <pre><code> select new { v.Value1, v.Value2, v.Value3, ... snip ... v.Value14, v.Value15, v.ValueTypeID }; </code></pre> <p>works because you are using the select new{} projection to return an anonymous type, which bypasses the identity map.</p> <pre><code> select v </code></pre> <p>selects the objects directly, which does use the identity map, causing the problem you were seeing.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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