Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have had almost exactly the same problem as you and have found the following solutions viable.</p> <p>Create SQL View</p> <pre><code>-- I'm guessing at the table join structure here create view LookupView as select t.TableName, ci.ColumnName, bi.Id, --This ID column needs to be the one used as the FK from other tables bi.*, --Or whatever columns you need coalesce(di.TextDescription, di.NumericDescription) as Description from TableInfo t join ColumnInfo ci on t.Id=ci.TableId join BusinessInfo bi on bi.Id=ci.BusinessId join LookupDescriptionInfo di on di.id=ci.id </code></pre> <p>Create base Lookup Class </p> <pre><code>public class Lookup { public virtual string Tablename {get; set;} public virtual string ColumnName {get; set;} public virtual string Description {get; set;} public virtual int Id {get; set;} //Other BusinessInfo properties } </code></pre> <p>Create a inherited LookupClass</p> <pre><code>public class ArmourLookup : Lookup{} </code></pre> <p>Use the ArmourLookup class on your business objects.</p> <pre><code>public class HeroArmour{ //Usual properties etc.... public virtual ArmourLookup Lookup {get; set;} } </code></pre> <p>Create a subclass discriminated mapping set</p> <pre><code>public class LookupMap : ClassMap&lt;Lookup&gt; { public LookupMap(){ Id(x=&gt;x.Id).GeneratedBy.Assigned(); //Needs to be a unique ID Map(x=&gt;x.Tablename); Map(x=&gt;x.ColumnName); Map(x=&gt;x.Description); //Business Info property mappings here Table("LookupView") DiscriminateSubClassesOnColumn&lt;string&gt;("ColumnName"); ReadOnly(); } } public class ArmourLookupMap : SubClassMap&lt;ArmourLookup&gt; { public ArmourLookupMap (){ DiscriminatorValue("ArmourColumn"); } } </code></pre> <p>Now you can repeat the subclass mapping for every column you have creating new types with ease. The issue here is that you cannot update or insert new lookups into the View so you are in a read-only mode.</p> <p>This method uses the column name as the discriminator so does away with the table name but if you have duplicate column names in your lookup table you could create a base lookup class for every table and specify a filter condition in the mapping.</p> <hr> <p>Another potential solution could be to use Enums generated by T4 templates from the lookup tables. Although this also is a read only approach.</p> <hr> <p>You could also map out each lookup table as a class and use the discriminator pattern to get different types from the ColumnInfo table.</p> <pre><code>public class TableInfo { public virtual int Id {get; set;} public virtual string Tablename {get; set;} public IList&lt;ColumnInfo&gt; Columns {get; set;} } public class ColumnInfo { public virtual int Id {get; set;} public virtual TableInfo TableInfo {get; set;} public virtual BusinessInfo BusinessInfo {get; set;} public virtual LookupDescriptionInfo LookupDescriptionInfo {get; set;} //Other properties } public class ArmourInfoColumn : ColumnInfo { //In the mapping you would discriminate on the columnname column. } etc... </code></pre> <p>Again optionally you can decide to discriminate out some XTable classes if you have duplicate column names in the column info table but different tableid's.</p> <p>You could also discriminate on the ColumnType (numeric or text) and subclass the LookupDescription class to use different columns for the "Description" property.</p> <p>If you could provide your table structure and some sample values I could flesh these ideas out more for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload