c# - Mapping foreign keys of subclasses -


i have following abstract class:

public abstract class clausecomponent     {         public int clausecomponentid { get; set; }         public abstract string[] determinate(climatechart chart);         public abstract list<clausecomponent> givecorrectpath(climatechart chart);          public abstract string gethtmlcode(boolean isyes);         public virtual void add(boolean soort, clausecomponent component)         {             throw new applicationexception();         }          public clausecomponent()         {          }     } 

the clause class inherits abstract class:

public class clause : clausecomponent     {          public virtual clausecomponent yesclause { get; set; }         public virtual clausecomponent noclause { get; set; }         public string name { get; private set; }          public virtual parameter par1 { get; set; }         public virtual parameter par2 { get; set; }         public int waarde { get; set; }         public string operator { get; set; }          public clause()         {         }          public clause(string name, parameter par1, string op, int waarde)         {             this.name = name;             this.par1 = par1;             this.operator = op;             this.waarde = waarde;         }          public clause(string name, parameter par1, parameter par2)         {             this.name = name;             this.par1 = par1;             this.par2 = par2;         } } 

this mapper of abstract class (i dont have mapper subclass):

public clausecomponentsmapper()         {             totable("clausecomponents");              // primary key             haskey(c => c.clausecomponentid);              // properties             property(c => c.clausecomponentid).hasdatabasegeneratedoption(databasegeneratedoption.identity);          } 

i have in db:

database values

now want give proper name mapping, how can accomplish this? have never done mapping on abstract classes , subclasses i'm little bit in blue here.

one way create properties mapping columns, , in mapping class, map virtual property using mapping column property.

e.g.

public class clause : clausecomponent {     public int mycustompar1id{ get; set; }      [foreignkey("mycustompar1id")]     public virtual parameter par1 { get; set; }        } 

or fluent api:

modelbuilder.entity<clause >().hasrequired(p => p.par1 ) // or optional             .hasforeignkey(p => p.mycustompar1id); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -