2016-09-16 1 views
0

ich einen Aufzählungstyp haben:NHibernate: Kartensammlung von Aufzählungen String und speichern als nvarchar mit

public enum CommunicationType 
{ 
    [Description("Callback to client")] 
    Callback 
} 

Welches Verwendung als Eigenschaft IList<CommunicationType> in Klasse Partner:

public class Partner 
{  
    public virtual long Id { get; set; } 
    public virtual IList<CommunicationType> CommunicationTypes { get; set; } 
} 

Meine PartnerMap Klasse sieht so aus:

public class PartnerMap : ClassMap<Partner> 
{ 
    public PartnerMap() 
    { 
     Schema("tm"); 
     Table("Partner"); 

     Id(x => x.Id); 

     HasMany(x => x.CommunicationTypes) 
      .Schema("tm") 
      .Table("PartnerCommunicationType") 
      .KeyColumn("PartnerId") 
      .Element("CommunicationType"); 
    } 
} 

Eins zu viele Beziehung zwischen Partner und CommunicationType i speichern in Tabelle [tm].[PartnerCommunicationType]:

PartnerId bigint 
CommunicationType nvarchar(256) 

Was mein Endziel ist: Aufzählungen als nvarchar-Wert zu speichern und sie von Tisch zu IList<CommunicationType> aus Spalte CommunicationType der Tabelle [tm].[PartnerCommunicationTypes kartieren.

Was ist mein Problem: String war in falschem Format.

enter image description here

Ich versuchte CommunicationType als einzelne Eigenschaft abzubilden Map(x=>x.CommunicationType) verwenden und das funktioniert gut, aber ich mit der Sammlung kann das nicht tun.

Gibt es eine Möglichkeit, ich könnte Sammlung von Enums zuordnen und es von Nvarchar zuordnen?

Bearbeiten: diese Antwort sollte mir helfen http://stackoverflow.com/a/22732415/2524304 aber ich kann nicht verstehen, wie könnte ich Typ mit FluentNHibernate setzen.

Antwort

0

Dies ist die Antwort: Fluent NHibernate - How map an IList<Enum> as list of strings

Sie haben NHibernate.Type.EnumStringType<T> mit Ihrer Art als Generika zu verwenden:

HasMany(x => x.CommunicationTypes) 
    .Schema("tm") 
    .Table("PartnerCommunicationType") 
    .KeyColumn("PartnerId") 
    .Element("CommunicationType", part => part.Type<EnumStringType<CommunicationType>>()); 
Verwandte Themen