none
Identity cache not used when entity has compound primary key RRS feed

  • Question

  • Hello, debugging a little complex application I found a strange behavior when retrieve an entity through a trivial LINQ expession like:

    Clave _clave = (from p in _context.Claves  where (p.PK == value1 && p.PK1 == value2) select p).First();

    I expected that the first time this query was executed, because there is no objects in the cache, LINQ should generate a SQL statement...OK, that's right! But the second time I hit the query, the statement was generate again..and again... and never retrieve the object from the cache...

    The table "Claves" has 2 fields PK and PK1 (only for testing purposes) both of them compunds the primary key.

    I try the same code without the compound PK and the behavior was the correct one...

    Apologizes by my bad english...and thanks for your attention.

    Best regards

    Enrique Thedy

     

    Friday, March 4, 2011 8:06 PM

All replies

  • Hello Enrique Thedy,

     

    Welcome to the MSDN Forum and thanks for posting here.

    According to your description and as I know in general, for a LINQ to SQL query to return an object from the identity cache, the query must be based on the primary key of an object and must return a single object.

    Pre-compiled queries will not return objects from the identity cache. For more information about pre-compiled queries, see CompiledQuery and How to: Store and Reuse Queries (LINQ to SQL).

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 8, 2011 4:58 AM
    Moderator