C#中,实体框架,自动递增的问题 [英] C#, entity framework, auto increment problem

查看:82
本文介绍了C#中,实体框架,自动递增的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆