标签:连接 添加 oid har nec ntc mod require nic
public class Student
{
public long Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public DateTime CreateTime { get; set; }
public short IsDelete { get; set; }
}
<!--数据库配置-->
<add name="consrt" connectionString="server=.;database=CodeFirstDB;uid=sa;pwd=123456" providerName="System.Data.SqlClient"/>
public class MyDbContext : DbContext
{
public MyDbContext()
: base("name=consrt")
{
}
/// <summary>
/// 创建数据库的策略
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
public DbSet<Student> Students { get; set; }
}
public class StudentConfig : EntityTypeConfiguration<Student>
{
public StudentConfig()
{
this.ToTable("Students");
this.Property(p => p.Name)
.HasMaxLength(30)//最大长度
.IsRequired()//不允许为空
.IsUnicode(false);// 是 varchar
this.Property(p => p.Address)
.HasMaxLength(100)//最大长度
.IsOptional()//允许为空
.IsUnicode(true)//是 n
.IsFixedLength();//固定长度 nchar(100)
}
}
标签:连接 添加 oid har nec ntc mod require nic
原文地址:https://www.cnblogs.com/Learnblog/p/9993208.html