Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 生成主键而不将其设置为键_Sql_Asp.net_Database_Entity Framework_Mvvm - Fatal编程技术网

Sql 生成主键而不将其设置为键

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; } }

在实体框架中创建表时,表中没有设置任何键。但是,当表在表中创建id字段并设置为键时,为什么

 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属性) 类将被推断为主键)。英孚还包括智能手机 用于连接模型之间关联关系的约定

有关更多信息:-