Open
Description
I have a IDictionary<IA, IB> dictionary in my class. I try to map this with FluentNHibernate but it creates a wrong mapping. The application shows that it generates a map using IA and IB instead of classes A and B. This is also clearly visible from the exported *.hbm.xml files. I am using Fluent-nhibernate 1.3.
The following code shows the problem:
using FluentNHibernate.Cfg;
using FluentNHibernate.Mapping;
using NHibernate;
using NHibernate.Cfg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public interface IA
{
int Id { get; set; }
string PropA { get; set; }
}
public interface IB
{
int Id { get; set; }
string PropB { get; set; }
}
public interface IC
{
int Id { get; set; }
IDictionary<IA, IB> Dictionary { get; set; }
}
public class A : IA
{
public virtual int Id { get; set;}
public string PropA { get; set; }
}
public class B : IB
{
public virtual int Id { get; set; }
public string PropB { get; set; }
}
public class C : IC
{
public virtual int Id { get; set; }
public virtual IDictionary<IA, IB> Dictionary { get; set; }
}
public class AMapper : ClassMap<A>
{
public AMapper()
{
Id(x => x.Id).GeneratedBy.Identity().Column("id");
Map(x => x.PropA).Column("propa");
}
}
public class BMapper : ClassMap<B>
{
public BMapper()
{
Id(x => x.Id).GeneratedBy.Identity().Column("id");
Map(x => x.PropB).Column("propa");
}
}
public class CMapper : ClassMap<C>
{
public CMapper()
{
Id(x => x.Id).GeneratedBy.Identity().Column("id");
HasMany<C>(x => x.Dictionary).Table("dict_table").AsEntityMap("C_id").KeyColumn("B_id");
}
}
class Program
{
static void Main(string[] args)
{
Configuration conf = new Configuration().Configure();
//configuration.AddAssembly(typeof(Program).Assembly);
var nhConfig = Fluently.Configure(conf)
.Mappings(mapping =>
{
mapping.FluentMappings.AddFromAssembly(typeof(A).Assembly);
mapping.FluentMappings.ExportTo(@"c:\temp\");
})
.ExposeConfiguration(cfg =>{});
Configuration configuration = nhConfig.BuildConfiguration();
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
sessionFactory.OpenSession();
}
}
}