简体   繁体   English

实体框架代码第一列名称问题

[英]Entity Framework Code First column name issue

I am having an issue with Entity Framework code first. 我首先遇到了Entity Framework代码的问题。

There is an existing column in my SQL database called 'myId'. 我的SQL数据库中有一个名为'myId'的列。 I am adding it to my class like so: 我将它添加到我的班级,如下所示:

public virtual int? myId { get; set; }

I run: update-database -connectionStringName '[SiteName]' -force 我运行:update-database -connectionStringName'[SiteName]' - force

All runs successfully but when I look in the database I see the existing column has been changed to 'myId1'. 所有运行成功,但当我查看数据库时,我看到现有列已更改为'myId1'。 I'm not sure why the name of my existing column is being changed and not used? 我不确定为什么现有列的名称被更改而未被使用? As you can see it has appended a '1' to the name....? 正如你所看到的,它在名称后附加了一个'1'。

Any ideas would be gratefully received! 任何想法都会感激不尽!

I assume myId is not PK!? 我认为myId不是PK!?


`public int? myId { get; set; }`

and add your migration as 并将您的迁移添加为


`AlterColumn("tablename", "myId", c => c.Int(nullable: true));`

Then run Update-database command. 然后运行Update-database命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM