c# - Schema specified is not valid. Errors: The relationship was not loaded because the type is not available -


i wish reference orderaddress model twice in order model; once shippingaddress , once billingadress.

on other side, want orderaddress model have list of orderaddresses.

orderaddress model


public enum addresstype {     billing,     shipping,     contact } public class orderaddress : basemodel {     public addresstype addresstype { get; set; }     public bool isprimary { get; set; }      public string address { get; set; }     public string citystatezip { get; set; }     public string contactname { get; set; }     public string phonenumber { get; set; }     public string faxnumber { get; set; }     public string emailaddress { get; set; }      public virtual icollection<order> orders { get; set; }      public virtual applicationuser user { get; set; } } 

order model


public class order : basemodel {     public datetime orderdate { get; set; }      public int billingaddressid { get; set; }     public virtual orderaddress billingaddress { get; set; }      public int shippingaddressid { get; set; }     public virtual orderaddress shippingaddress { get; set; }      public virtual applicationuser user { get; set; }  } 

fluent api


protected override void onmodelcreating(dbmodelbuilder modelbuilder) {     base.onmodelcreating(modelbuilder);      modelbuilder.entity<order>()                 .hasrequired(m => m.shippingaddress)                 .withmany(t => t.orders)                 .hasforeignkey(m => m.shippingaddressid)                 .willcascadeondelete(false);      modelbuilder.entity<order>()                 .hasrequired(m => m.billingaddress)                 .withmany(t => t.orders)                 .hasforeignkey(m => m.billingaddressid)                 .willcascadeondelete(false); } 

when try run update-database, following error:

schema specified not valid. errors: relationship 'myapp.domain.dal.order_shippingaddress' not loaded because type 'myapp.domain.dal.orderaddress' not available.

what doing wrong?

the error little cryptic, i'm not sure if reason you're getting particular error, know cause some error, can start fixing this:

what have 2 one-to-many relationships same model on 1 class. that's not problem per se, have treat them separate. in other words, can't both have opposite relationship of orders, because relationally, there's no way know foreign key relationship should populate list. if change fluent api definition .withmany(t => t.orders_shipping) , .withmany(t => t.orders_billing), think clear error.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -