首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

entity framework(EF)_code first复杂类型(Complex Types)有关问题

2012-04-05 
entity framework(EF)_code first复杂类型(Complex Types)问题C# codepublic class Address{public string

entity framework(EF)_code first复杂类型(Complex Types)问题

C# code
public class Address    {       public string FirstName { get; set; }       public string LastName { get; set; }       public string Addr { get; set; }       public string Street { get; set; }       public string City { get; set; }       public string ZipCode { get; set; }       public string Email { get; set; }       public string Phone { get; set; }       public string State { get; set; }       public string Country { get; set; }    }

C# code
public class Order    {       public int OrderId { get; set; }       public string OrderNumber { get; set; }       public DateTime OrderData{get;set;}       public string DisposeDate { get; set; }       public Address ShipAddress { get; set;}       public Address BillAddress { get; set; }}

C# code
  //然后我们modelbuilder //BillAddress            modelBuilder.Entity<Order>().Property(i => i.BillAddress.Addr).HasColumnName("BillAddr")                .HasMaxLength(128);//A:注意这里            modelBuilder.Entity<Order>().Property(i => i.BillAddress.Street).HasColumnName("BillStreet")                .HasMaxLength(128);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.City).HasColumnName("BillCity")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.ZipCode).HasColumnName("BillZipCode")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.State).HasColumnName("BillState")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.Country).HasColumnName("BillCountry")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.Email).HasColumnName("BillEmail")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.Phone).HasColumnName("BillPhone")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.FirstName).HasColumnName("BillFirstName")                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.BillAddress.LastName).HasColumnName("BillLastName")                .HasMaxLength(50);            //ShipAddress                     modelBuilder.Entity<Order>().Property(i => i.ShipAddress.Addr).HasColumnName("ShipAddr")               .HasMaxLength(128)               .IsRequired();//B:注意这里            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.Street).HasColumnName("ShipStreet")                //.IsRequired()                .HasMaxLength(128);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.City).HasColumnName("ShipCity")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.ZipCode).HasColumnName("ShipZipCode")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.State).HasColumnName("ShipState")               // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.Country).HasColumnName("ShipCountry")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.Email).HasColumnName("ShipEmail")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.Phone).HasColumnName("ShipPhone")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.FirstName).HasColumnName("ShipFirstName")                // .IsRequired()                .HasMaxLength(50);            modelBuilder.Entity<Order>().Property(i => i.ShipAddress.LastName).HasColumnName("ShipLastName")                 //.IsRequired()                .HasMaxLength(50); 


生成的数据库为

不知道你注意到了吗,两个地方都为不允许为空,怎么回事,求解..
http://www.cnblogs.com/xcj1989/archive/2012/03/16/2400658.html


[解决办法]
因为不能为空,所有不能为空

热点排行