none
Primary Keys (EDM)

    Вопрос

  •  

    Hi,

     

    I got this error when generating an EDM with a table without a primary key with our custom EF provider:

     

    <!--Errors Found During Generation:

    warning 6013: The table/view 'PUBLIC.STUDENTSADDRESSES' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity you will need to review your schema, add the correct keys and uncomment it.

     

    I'm importing a table which I want to iterate through and do nothing else.

     

    Are "keys" an absolute requirement in generating entities? Is there a way around this without changing the underlying schema?

     

    One other thing, our database supports nullable columns for the keys, is there a way to disable the rule in the EDM code generation that checks these?

     

    Regards,

    Ayee

    6 октября 2008 г. 16:55

Ответы

  • The framework requires each entity to have a key. If no key is defined in the in the database object (like a view, or, as in your case, a table with no key), the tools try to infer a key based on the columns of the table or view (at least one non-binary, non-nullable column is required to infer a key). When no key can be inferred, a code comment that contains the corresponding EntityType element (with no Key elements) is added to the SSDL section of the .edmx file.

     

    In your case, since it seems that you want a read only entity, you could...

    1) uncomment the SSDL entity

    2) mark one/some properties as Nullable="False"

    3) add the appropriate Key elements

    4) add a corresponding defining query. 

     

    I posted more detail in this forum thread about how to add a defining query.

     

    Hope that helps.

    -Brian 

    7 октября 2008 г. 21:37

Все ответы

  • I think this is the same issue addressed here: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3966067&SiteID=1

     

    Let me know if it is not.

     

    -Brian

    6 октября 2008 г. 22:16
  • There is a subtle difference between this and that one. It's possible to infer the keys for a view but in this case, this table by nature has no keys. The scenario for this would be; a database does not require me to give a table a key when i create one; so how do I justify that my entities have to have keys when the tables at the backend don't have any?

    -Ayee

    7 октября 2008 г. 16:55
  • The framework requires each entity to have a key. If no key is defined in the in the database object (like a view, or, as in your case, a table with no key), the tools try to infer a key based on the columns of the table or view (at least one non-binary, non-nullable column is required to infer a key). When no key can be inferred, a code comment that contains the corresponding EntityType element (with no Key elements) is added to the SSDL section of the .edmx file.

     

    In your case, since it seems that you want a read only entity, you could...

    1) uncomment the SSDL entity

    2) mark one/some properties as Nullable="False"

    3) add the appropriate Key elements

    4) add a corresponding defining query. 

     

    I posted more detail in this forum thread about how to add a defining query.

     

    Hope that helps.

    -Brian 

    7 октября 2008 г. 21:37
  • The link in "this forum thread" is no longer valid.
    24 февраля 2012 г. 17:11