Suppose I have a few definitions like so:
public interface ICategory
{
int ID { get; set; }
string Name { get; set; }
ICategory Parent { get; set; }
}
public class Category : ICategory
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
public virtual ICategory Parent { get; set; }
}
How do I map such a scenario in NHibernate/EF 4? I am trying to separate the implementation of the DAL.
I am learning NHibernate, EF 4.
Regards,
Karan
NHibernate has issues mapping interfaces to tables.
We’ve gotten around it by creating a protected variable of the concrete type which is used for mapping, and exposing the interface type as a getter/setter for that concrete type:
(That code is off the top of my head – I’m confident it will have a syntax error hidden in it, but the idea is there).
Its not the prettiest implementation and it feels ugly, but it works. Perhaps someone else will see this and have an alternative :).