C#中,实体框架,自动递增的问题 [英] C#, entity framework, auto increment problem
问题描述
我在VC#2010学习实体框架。
我创建了一个简单的表,学习之用,其中一个字段是ID整型,同一性设置为true。我从表生成实体数据模型,并与连接的dataGridView它。的问题是,它没有自动增量 - 每个插入行希望成为的id = 0(这是不可能当然,由于ID必须是唯一的)
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, indentity 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)
我是什么做错了吗?我应该怎么配置EF或SQL数据库本身?
what am I doing wrong? how should I configure EF or the SQL db itself?
感谢
推荐答案
检查您的EDMX模式,即自动增量字段的StoreGeneratedPattern属性设置为身份。以这种方式,EF知道该autonumbers通过DB处理
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.
下面是这样解释更好:<一href=\"http://stackoverflow.com/questions/3011764/autonumber-with-entity-framework/3038265#3038265\">http://stackoverflow.com/questions/3011764/autonumber-with-entity-framework/3038265#3038265
这篇关于C#中,实体框架,自动递增的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!