locked
Map a table without a primary key? RRS feed

  • Question

  • Hi,

    After looking around in this forum I still haven't found a clear answer to how to handle tables that has no primary key. I have a legacy database project that I'm mapping to entity framework 4 ctp 4.
    The table consist of only 2 integers values but no primary key and therefore I get the error "Unable to infer a key for entity type".

    So is the solution to make one of them the primary key?

     

    Friday, November 5, 2010 3:34 PM

Answers

  • Hi,

    Yes, currently Code First only supports  mapping to read/write tables (i.e. with a primary key). If you are mapping to an existing database then the column(s) don't actually have to literally be a primary key in the database, they just need to be unique.

    ~Rowan

    Friday, November 5, 2010 5:15 PM
    Moderator