0
votes

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 ?

1

1 Answers

2
votes

A nice article on how to do it: http://www.philliphaydon.com/2011/08/fluent-nhibernate-table-inheritance-discriminators/

You are looking at a table-per-hierarchy strategy.

In a nutshell you use:

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");
            ...
        }
    }