Sql 生成主键而不将其设置为键
在实体框架中创建表时,表中没有设置任何键。但是,当表在表中创建id字段并设置为键时,为什么Sql 生成主键而不将其设置为键,sql,asp.net,database,entity-framework,mvvm,Sql,Asp.net,Database,Entity Framework,Mvvm,在实体框架中创建表时,表中没有设置任何键。但是,当表在表中创建id字段并设置为键时,为什么 public class EntityBase { public long Id { get; set; } public DateTimeOffset? DeletedOn { get; set; } public string RefId { get; set; } public DateTimeOffset CreatedOn { get; set; } }
public class EntityBase
{
public long Id { get; set; }
public DateTimeOffset? DeletedOn { get; set; }
public string RefId { get; set; }
public DateTimeOffset CreatedOn { get; set; }
}
如前所述,实体框架根据理想的命名自动识别主键,如您的案例中的Id
:-
如文件所述:-
EF支持的其他默认约定包括
基于公共密钥自动识别主键和外键
命名模式(例如:晚餐上的ID或DinnerID属性)
类将被推断为主键)。英孚还包括智能手机
用于连接模型之间关联关系的约定
有关更多信息:-