c# - EF 4.1 Code First Mapping Problem -


all attempts map id of sitepage database column id (sitepages table, id column of type bigint) has failed. keeps looking column sitepage_id map it.. can see doing wrong? related code below;

public class site : entitybase<int64> {     public virtual string url { get; set; }     public virtual ilist<sitepage> pages { get; set; } }  public class sitepage : entitybase<int64> {     public virtual site site { get; set; }      public virtual string url { get; set; }     public virtual string html { get; set; }     public virtual string text { get; set; }     public virtual string language { get; set; } }  public abstract class entitybase<t> : icomparable {      public virtual t id { get; set; }      protected entitybase() : this(default(t))      {      }      protected entitybase(t id)     {         this.id = id;          if (this.id == null)             this.id = default(t);     } }  public class spellcrawlercontext : dbcontext {     public spellcrawlercontext(){}      public dbset<site> sites { get; set; }      public dbset<sitepage> sitepages { get; set; }       protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         modelbuilder.entity<site>()             .hasmany(s => s.pages)             .withrequired(p => p.site)             .map(s => s.mapkey("siteid"));          modelbuilder.entity<sitepage>()             .haskey(p => p.id);          modelbuilder.entity<sitepage>()             .property(p => p.id)             .hascolumnname("id");      } } 

you not doing wrong. code shown correctly. don't need explicitly define name of id in sitepage because defined id anyway.

sitepage_id used default naming convention foreign keys created independent associations. have other one-to-many relation between sitepage , other entity? if didn't map foreign key in dependent entity defined sitepage_id default.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -