Fluent NHibernate HasMany where source is a comma separated string of Ids
Im' trying to wrap my head around fluent nHibernate while trying to do this kind of mapping:
public class ClassA : Entity
{
publ开发者_StackOverflowic virtual string SomeField { get; set; }
}
public class ClassB : Entity
{
public virtual string ClassAIds { get; set; }
public virtual IList<ClassA> ClassAList { get; set; }
}
Where Entity basically ensures that both classes have Id field as their primary database key.
Database would look like:
table ClassA:
int Id,
varchar(25) SomeField
table ClassB:
int Id,
varchar(50) ClassAIds
I'm trying to write some map so that ClassB object would be populated with ClassA entities into ClassAList. Is it possible to have something similar to:
public void Override(AutoMapping<ClassB> mapping)
{
mapping.HasMany(x => x.ClassAIds.Split(new char[] { ',' }).Select(i => int.Parse(i)).ToList()).KeyColumn("Id");
}
I don't really understand how to pass a target class type and if it is possible to achieve this at all.
I don't think you can do what you are asking. I think your best bet would be to map it as it appears in the database and handle the loading of that ClassAList collection outside of the mapping. I would set your automapping up to ignore the collection. This is just not really a good way to handle relationships from a database perspective.
精彩评论