简体   繁体   中英

How to map IDictionary<Enum, bool>?

How do I map Dictionaries with FluentNHibernate?

IDictionary<SomeEnum, bool>

and..

IDictionary<string, bool>

?

like:

public class SomeClass
{    
   public int Id {get;set;}
   public IDictionary<SomeEnum, bool> Dictionary2 {get;set;} 
   public IDictionary<string, bool> Dictionary1 {get;set;} 
}

It seems the mapping for Dictionary can be done as follows:

// IDictionary<string, bool>
HasMany(x => x.Dictionary1).AsMap<string>("keyColumn").Element("Enabled");

// IDictionary<SomeEnum, bool>  (Enum will be mapped as int)
HasMany(x => x.Dictionary2).AsMap("SomeEnum").Element("Enabled");  

// IDictionary<Entity, string>
HasMany(x => x.Dictionary3).AsEntityMap().Element("valueColumn"); 

As far as I know, you can't map dictionary to the database. Moreover, there is no equivalent for enum in SQL Server. To implement IDictionary<string, bool> , I guess, you need to create separate table, that will contain Id, your String, Boolean values and FK to SomeClass (many-to-one relationship). With enum dictionary is the same case, but the contents of that foreign table depends on your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM