create entity with both primary key and identity column in EF6

坚强是说给别人听的谎言 提交于 2019-12-10 10:12:43

问题


I already have a table with a varchar Primary Key. This is working fine with my current .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

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


回答1:


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



回答2:


It should not be the problem. Save your database table with the new column, delete and recreate .edmx. Hope it'll be done.



来源:https://stackoverflow.com/questions/47015070/create-entity-with-both-primary-key-and-identity-column-in-ef6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!