c# - Entity Framework Code First Database Initialization with relations -


i'm working on n-teir project , question focusing on service (buisness logic) , data layers. have in data layer, 3 models: aircraft, aircrafttype, , aircraftlivery. have pretty idea of how initialize database sample data, i'm unsure of how relate different types. how create livery , relate aircraft, or default livery of aircraft type? how relate aircraft type aircraft? below current code builds havn't ran yet. how implement last class, sample data? there else in code see done differently?

in data layer:

    public abstract class modelbase     {         [key]         public int id { get; set; }         public string lastupdateuser { get; set; }         public datetime lastupdatedt { get; set; }         public bool isdeleted { get; set; }     }      public class aircraft : modelbase     {         public guid serialnumber { get; set; }         public string registration { get; set; }         public byte[] image { get; set; }         [foreignkey("id")]         public aircrafttype type { get; set; }         [foreignkey("id")]         public aircraftlivery livery { get; set; }     }      public class aircrafttype : modelbase     {         public string manufacture { get; set; }         public string icao { get; set; }          public string name { get; set; }           public bool istaildragger { get; set; }         public bool retractablegear { get; set; }          public double stallspeedfullflaps { get; set; }         public double stallspeedclean { get; set; }         public double cruisespeed { get; set; }         public double minimumdragvelocity { get; set; }         public int lowerthrottlelimit { get; set; }         public int maximummachspeed { get; set; }           public int range { get; set; }         public int weight { get; set; }         public int cruise { get; set; }         public int maximumpassengers { get; set; }          [foreignkey("id")]         public icollection<aircraftlivery> liveries { get; set; }         [foreignkey("id")]         public aircraftlivery defaultlivery { get; set; }     }      public class aircraftlivery : modelbase     {         public byte[] image { get; set; }         public string name { get; set; }         [foreignkey("id")]         public aircrafttype aircrafttype { get; set; }         [foreignkey("id")]         public icollection<aircraftlivery> aircrafts { get; set; }         public string author { get; set; }     }      public class sampledata : dropcreatedatabaseifmodelchanges<airlinecontext>     {         protected override void seed(airlinecontext context)         {             var aircraft = new list<aircraft>             {                 //new aircraft() {},             };              var aircrafttypes = new list<aircrafttype>             {                 //new aircrafttype() {},             };              var aircraftliveries = new list<aircraftliveries>             {                 //new aircraftliveries() {},             };         }     } 

in service:

    public class global : system.web.httpapplication     {         protected void application_start(object sender, eventargs e)         {         database.setinitializer(new sampledata());         }     } 

just simple hint, hope help.

public class aircraft : modelbase {         public guid serialnumber { get; set; }         public string registration { get; set; }         public byte[] image { get; set; }          //this foreignkey aircrafttype         public int aircrafttypeid {get;set;}          //this foreignkey aircraftlivery         public int aircraftliveryid {get;set;}          //instead of id use aircrafttypeid         [foreignkey("aircrafttypeid")]         public aircrafttype type { get; set; }         [foreignkey("aircraftliveryid")]         public aircraftlivery livery { get; set; } } 

for collection have use icollection. e.g.

public class category {      [key]      public int id{get;set;}       public string name {get;set;}       public icollection<subcategory> subcategories{get;set;} }  public class subcategory {      [key]      public int id{get;set;}       public string name {get;set;}       public int categoryid {get;set;}       [foreignkey("categoryid")]      public category category {get;set;} } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -