Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, entity framework, auto increment

I'm learning Entity Framework under VC# 2010.

I have created a simple table for learning purposes, one of the fields is "id" type integer, identity set to true. I've generated Entity Data Model from that table and connected it with dataGridView. The problem is that it doesn't auto increment - each inserted row wants to be id=0 (which is impossible of course, since id must be unique)

What am I doing wrong? How should I configure EF or the SQL db itself?

like image 494
migajek Avatar asked Jul 06 '10 16:07

migajek


1 Answers

Check in your EDMX model, that the autoincrement field's StoreGeneratedPattern attribute is set to "Identity". In this way, EF knows that the autonumbers are handled by the DB.

Here this is explained better: Autonumber with Entity Framework

like image 166
cepriego Avatar answered Sep 20 '22 11:09

cepriego