Bill Gates, 1984
“To create a new standard, it takes something that’s not just a little bit different, it takes something that’s really new and really captures people’s imagination and the Macintosh, of all the machines I’ve ever seen, is the only one that meets that standard.”
Mapping simple IDictionary with fluent NHibernate
Database schema

Domain entity
public class Issue : EntityBase
{
public Issue()
{
this.CustomFields = new Dictionary<string, string>();
}
// other properties
public virtual IDictionary<string, string> CustomFields
{
get;
set;
}
}
Fluent mapping
public class IssueMap : ClassMap<Issue>
{
public IssueMap()
{
Id(x => x.Id).GeneratedBy.Guid();
// other mappings
HasMany(x => x.CustomFields)
.WithTableName("IssueMetadataValue")
.KeyColumnNames.Add("IssueId")
.Cascade.All()
.AsMap<string>(
index => index.WithColumn("Name").WithType<string>(),
element => element.WithColumn("Value").WithType<string>()
);
}
}
Create NHibernate session factory with fluent mappings
Fluent NHibernate introduces ClassMap to replace HBM mapping files and these mappings must be located in the creation of NHibernate session factory. HBM mappings are built as resources of an assembly being specified in configuration file. Fluent NHibernate also requires an assembly containing fluent mappings.
public static ISessionFactory CreateSessionFactory()
{
var sessionFactory = Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.Is(System.Configuration.ConfigurationManager
.ConnectionStrings["DolphinConnection"].ConnectionString)
)
)
.Mappings(
m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())
)
.BuildSessionFactory();
return sessionFactory;
}
Assembly.GetExecutingAssembly() returns executing assembly where fluent mappings are defined within.