且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

复杂类型的流畅api不能正常工作

更新时间:2022-10-20 12:45:30

这很糟糕!


随时改变怎么c.Billingddress.Addr影响c.ShippingAddrress.Addr


没有意义!


I have a complex type which is used twice on an entity. For instance customer has billing and shipping address. By default code first, makes all the properties of the complex type as not required so the database columns are marked as nullable. So far so good. Now i want to make billingaddress be required but if the shipping address is not present, its okay.. when i configure BillingAddress properties as required, it also forces the shippingaddress properties as required. below should not affect the shippingaddress and shippingaddress should generate nullable columns.

 

protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)

        {

            var cust = modelBuilder.Entity<Customer>();

            cust.Property(c => c.BillingAddress.Addr).HasColumnName("BillingAddr").IsRequired();

            cust.Property(c => c.BillingAddress.City).HasColumnName("BillingCity").IsRequired();

            cust.Property(c => c.BillingAddress.State).HasColumnName("BillingState").IsRequired();

            //EF also maes ShippingAddr,ShippingCity and ShippingState as also required.not good

            cust.Property(c => c.ShippingAddress.Addr).HasColumnName("ShippingAddr");

            cust.Property(c => c.ShippingAddress.City).HasColumnName("ShippingCity");

            cust.Property(c => c.ShippingAddress.State).HasColumnName("ShippingState");

                       

        }

 

Help!


Zeeshan Hirani Entity Framework 4.0 Recipes by Apress
http://weblogs.asp.net/zeeshanhirani

this sucks!

anytime i change how c.Billingddress.Addr it affects c.ShippingAddrress.Addr

doesn't make sense!