简体   繁体   中英

Entity Framework Code First column name issue

I am having an issue with Entity Framework code first.

There is an existing column in my SQL database called 'myId'. I am adding it to my class like so:

public virtual int? myId { get; set; }

I run: 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'. 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....?

Any ideas would be gratefully received!

I assume myId is not PK!?


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

and add your migration as


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

Then run Update-database command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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