复杂类型的流畅api不能正常工作 [英] fluent api for complex type does not work properly

查看:66
本文介绍了复杂类型的流畅api不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在实体上使用两次的复杂类型。例如,客户有账单和送货地址。默认情况下,首先将复杂类型的所有属性设置为不需要,以便将数据库列标记为可为空。到目前为止,所以
好​​。现在我想要使用billingaddress,但是如果发货地址不存在,那就没问题......当我根据需要配置BillingAddress属性时,它还会根据需要强制使用shippingaddress属性。下面不应该影响shippingaddress
和shippingaddress应该生成可以为空的列。


 



< p style ="margin-bottom:.0001pt; line-height:normal; text-autospace:none"> protected
覆盖 空隙 OnModelCreating(System.Data.Entity.ModelConfiguration的模型构建器模型构建器)


   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
{


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


           
c​​ust.Property(C => c.BillingAddress.Addr).HasColumnName(的" BillingAddr" )IsRequired();


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


           
c​​ust.Property(C => c.BillingAddress.State).HasColumnName(的" BillingState" )IsRequired();


           
// EF也可以使ShippingAddr,ShippingCity和ShippingState符合要求。不好


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
c​​ust.Property(C => c.ShippingAddress.Addr).HasColumnName(的" ShippingAddr" );


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


           
c​​ust.Property(C => c.ShippingAddress.State).HasColumnName(的" ShippingState" );


<跨度风格="">&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;


       
}


 


帮助!



Zeeshan Hirani Apress的实体框架4.0食谱


http://weblogs.asp.net/zeeshanhirani

解决方案

这很糟糕!


随时改变怎么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!


这篇关于复杂类型的流畅api不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆