C#,实体框架,自动增量 [英] C#, entity framework, auto increment

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

问题描述

我正在VC#2010下学习实体框架。



我已经创建了一个用于学习目的的简单表,其中一个字段是id类型的整数,身份设置为true。我从该表生成了实体数据模型,并将其与dataGridView连接起来。问题是它不会自动递增 - 每个插入的行都想要id = 0(当然这是不可能的,因为id必须是唯一的)



什么是我做错了吗如何配置EF或SQL数据库本身?

解决方案

检查您的EDMX模型,自动增量字段的StoreGeneratedPattern属性设置到身份。以这种方式,EF知道自动登录器由DB处理。



这里更好地解释:使用实体框架的自动编号


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?

解决方案

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

这篇关于C#,实体框架,自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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