在EF6中同时创建具有主键和标识列的实体 [英] create entity with both primary key and identity column in EF6

查看:248
本文介绍了在EF6中同时创建具有主键和标识列的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个带有varchar主键的表.使用我当前的.edmx可以正常工作.

I already have a table with a varchar Primary Key. This is working fine with my current .edmx.

现在,我在该表中添加了自动删除身份列.当我尝试更新.edmx时,该表未包含在.edmx

Now I added an auto-increament identity column in that table. While I try to update the .edmx, that table is not being included in .edmx

我不能在同一张表中放置varchar PK列和自动删除身份列吗?

Can't I put a varchar PK column and an auto-increament identity column in the same table?

推荐答案

是的,这是一个示例.身份属性与PK无关.显然,它永远不会为空,并且会根据您设置的值从种子开始递增.

Yes, here's an example. The identity property has nothing to do with the PK. It just won't ever be null, obviously, and increments from the seed based off what ever you set.

create table myTable ( VC varchar(64) not null
                        ,primary key (VC)
                        )

insert into myTable
values
('something')
,('else')


select * 
from myTable

alter table myTable
add id int identity (1,1)


insert into myTable (VC)
values
('thirdColumn')


select * 
from myTable

这篇关于在EF6中同时创建具有主键和标识列的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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