views:

80

answers:

1

Hello guys,

I'm having a problem with the Create method of the NerdDinner tutorial, which is very good BTW.

As you can see here http://nerddinnerbook.s3.amazonaws.com/Part5.htm in the Create method, he removed the ID field of the aspx page.

I did that too, but I cannot add any dinners because I get a primary key violation.

How is NerdDinner controlling the ids of each dinner? I revised the tutorial and could not see any references to identity fields on SQL database.

I even created a method to get me the highest id in the table:

    public int GetHighestDinnerId()
    {
        int resultado = (from dinner in dataContext.Dinners
                         select dinner.DinnerId).Max();
        return resultado;
    }

which does not work either.

Any thoughts?

Thank you

A: 

Heya, I'm just speculating here but I assume that the primary key should have the Auto-generated value property set to true so you don't have to explicitly set it, it gets generated for you on insert. You should be able to configure that within the dbml.

EDIT: Just looked through the NerdDinner tutorial and if you look at step 2, it talks about setting the ID column as an identity column so the value is auto-generated which is probably where you want to configure it.

Wysawyg
Thanks. I guess that just passed by me :D
George