EntityFramwork常见问题

1.经常使用的语句有哪些数据库

 添加migration      dotnet ef migrations add [MIgrationName]code

删除刚添加的migration      dotnet ef migrations removerem

更新数据库    dotnet ef database update、字符串

2.在代码中用 attribute (code first) 限制表中字段的类型及主外键get

主键      [Key]
自增加  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]it

外键     [ForeignKey("【主表名】")]io

字符串类型   [Column(TypeName = "NVARCHAR(50)")]date

3.更新数据库报错 String or binary data would be truncated. The statement has been terminated.List

 多半是字符串长度改短了 数据库中存在长字符串数据
 根据migration的提交记录看最后一次 哪些字段改了类型进行比对数据

4.如何添加外键

 添加外键的时候须要在主表中添加对应的从表的ICollection或者属性字段

  一对多  public ICollection<OrderDtl> OrderDtlList { get; set; }  

  一对一  public ExpressInfo ExpressInfo { get; set; } 

相关文章
相关标签/搜索