有什么方法可以控制EF在我的代码第一个定义的表上创建的PK索引的名称?
Yes, you can name it anything you like and put [Key]
attribute on it.
So if you have a model Person
as below, you won't need anything like [Key]
, iicallyt will treat PersonId
as PK automatically with the convention {classname}Id
public class Person
{
public int PersonId { get;set; }
public int FirstName { get; set; }
}
If you want to have some different PK, then you can specify it with [Key] as below:
public class Person
{
[Key]
public int YourPK{ get;set; }
public int FirstName { get; set; }
}
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.