EF Code First属性规则及配置
来源:互联网 发布:c语言成绩管理系统6.0 编辑:程序博客网 时间:2024/06/08 13:29
转载地址:http://www.cnblogs.com/libingql/archive/2012/03/27/2420225.html
EF Code First的属性规则及配置主要分为以下内容:
1、长度
Data Annotation:MinLength(n)、MaxLength(n)、StringLength(n)
Fluent:Entity<T>.Property(t=>t.PropertyName).HasMaxLength(n)
2、数据类型
Data Annotation:Column(TypeName=“xxx”)
Fluent:Entity<T>.Property(t=>t.PropertyName).HasColumnType (“xxx”)
3、不可空
Data Annotation:Required
Fluent:Entity<T>.Property(t=>t.PropertyName).IsRequired()
4、主键
Data Annotation:Key
Fluent:Entity<T>.HasKey(t=>t.PropertyName)
非默认惯例属性主键设置,即属性名称不为ID或[类名]ID:
1 [Key]
2 public Guid Identifier { get; set; }
1 modelBuilder.Entity<Category>().HasKey(t => t.Identifier)
5、数据库自动生成值
1 [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
2 public Guid Identifier { get; set; }
1 modelBuilder.Entity<Trip>()
.HasKey(t => t.Identifier)
.Property(t => t.Identifier)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
6、Decimal精度
Data Annotation:不支持
Fluent:Entity<T>.Property(t=>t.PropertyName).HasPrecision(m,n)
分类: EF Code First
0 0
- EF Code First属性规则及配置
- EF Code First默认规则及配置
- EF Code First数据库连接配置
- EF Code First 学习笔记:约定配置
- EF Code First 学习笔记:约定配置
- EF Code First 学习笔记:约定配置
- ef-->code first-->Migrations
- ef code first例子
- EF Code first
- EF(code First)
- EF Code First 常用命令
- EF code first attribute
- EF Code First
- EF code First
- EF Code First 导航属性 与外键 学习笔记
- EF 4.1 Code First Walkthrough
- EF Code First 初体验
- EF Code First 初体验
- Tiny界面编辑器
- 关于AVCapture编程理解 (可以与UIImagePickerController进行比较)
- 2014年最受开发者好评的混合应用UI框架大比拼
- Tiny流程编辑器
- Python3 中文使用以及中文乱码问题
- EF Code First属性规则及配置
- 浪漫情书+部份分析
- 级联
- 网神点燃互联网+国家政务安全日
- Tiny服务编辑器
- CF305 Mike and Feet 单调栈(求每个长度对应的最小数字)
- Qt中设置widget背景颜色背景图片的注意事项
- 基于jquery的$.ajax async使用
- Tiny模板运行器