0

Im working on rebuilding a clients software and they want to keep their database as unmodified as possible.

I got a table where they collect users and orders for different companies, no biggie there but the twist is they do it for multiple entities.

for example the table looks like this:

  • ID
  • UserID
  • Index
  • CompanyID
  • Type

lets say they got entities like Project and Workflow, then the Type column would be 'P' for projects and 'W' for workflows. So on a ID is the ID of a Project or Workflow Identity. UserID is always a foreign key to a User entity and Index is the order that the user is used when this Project/Workflow is used. And CompanyID is what company owns project or workflow entity.

I have tried to search google for this but i came up with nothing.

What i want is on a Template entity map two collections say StandardProjectUsers and StandardWorkflowUsers and they should collect them from correct entities with a user and index for current company.

Is this at all possible with fluent nhibernate ?

4

1 回答 1

2

一篇关于如何做到这一点的好文章:http ://www.philliphaydon.com/2011/08/fluent-nhibernate-table-inheritance-discriminators/

你正在寻找一种table-per-hierarchy策略。

简而言之,您使用:

public class BaseClassMap : ClassMap<BaseClass>
{
    public BaseClassMap()
    {
        DiscriminateSubClassesOnColumn("Type");
        ...
    }
} 

public class WorkflowMap : SubclassMap<Workflow>
{
    public WorkflowMap()
    {
        DiscriminatorValue("W");
        ...
    }
}

public class ProjectMap : SubclassMap<Project>
    {
        public ProjectMap()
        {
            DiscriminatorValue("P");
            ...
        }
    }
于 2013-08-27T12:27:04.923 回答