开发者

Mapping abstract base classes using Fluent NHibernate Automapper

I'm using Fluent NHibernate's automapper to map the following domain model (via AutoMap开发者_如何学Python.AssemblyOf<Ticket>()), but it's throwing an exception when creating a SessionFactory.

class Ticket {
    Owner TicketOwner { get; set; }
    Owner CreatedBy { get; set; }
}
abstract class Owner {
    ICollection<Ticket> OwnedTickets { get; set; }
    ICollection<Ticket> CreatedTickets { get; set; }
    string Name { get; set; }
}
class Person : Owner {
    Department EmployeeDepartment { get; set; }
    // ...
}
class Department : Owner {
    ICollection<Person> People { get; set; }
    // ...
}

NHibernate.MappingException: An association from the table Ticket refers to an unmapped class: Owner

The documentation says that this should work as-is. Am I forgetting something?


When you define your base class to be abstract, NHibernate does not generate any table for it. Thus, you cannot refer to that class from Ticket.

So, you need to create it as non-abstract and accept the extra table in your database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜