none
L2S + SQLCE, Table does not have a primary key error RRS feed

  • Question

  • I have seen others that have this problem when calling InsertOnSubmit and they have to add a key, but I already have one and get the error. I am using a SQLCE database in a well known location that is being explicitly loaded in the connection string. I can perform operations on the database(I truncate all the tables at the start of this test via ExecuteCommand)  so I know the load is working correctly, but I get this missing key error when I call InsertOnSubmit, if I load up the .sdf file in Server Explorer I cna browse to the table and it has a primary key icon on the correct field and the table properties also show this.

    I know this is hard to believe but is there anything else that would trigger this error?
    Wednesday, August 26, 2009 7:35 PM

Answers

  • please confirm the following:
    - the primary key is defined on the table
    - is this auto generated or you manually enter this value?
    - If auto generated in DB, then look at the designer file
    - does the designer file has the correct attribute specified?

    it should look something like this:

    [

    Column(Storage = "_OrgEntityTypeID", AutoSync = AutoSync.OnInsert, DbType = "BigInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]


    Happy coding!
    kashif
    • Marked as answer by CFandango Wednesday, August 26, 2009 9:12 PM
    Wednesday, August 26, 2009 8:42 PM

All replies

  • please confirm the following:
    - the primary key is defined on the table
    - is this auto generated or you manually enter this value?
    - If auto generated in DB, then look at the designer file
    - does the designer file has the correct attribute specified?

    it should look something like this:

    [

    Column(Storage = "_OrgEntityTypeID", AutoSync = AutoSync.OnInsert, DbType = "BigInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]


    Happy coding!
    kashif
    • Marked as answer by CFandango Wednesday, August 26, 2009 9:12 PM
    Wednesday, August 26, 2009 8:42 PM
  • PERFECT!

    It was point number 4, the attribute was missing as I had not regenerated the file since adding the primary key, knew it was going to be something simple and stupid!
    Wednesday, August 26, 2009 9:12 PM