Hi Guido,
Sorry for not replying sooner, I read your post and made note to reply later
and never did!
I've been looking at your schema, and I think there are a few ways you could
make things easier. Have you considered giving act a direct reference to prj,
then using a subclass mapping to create a Coding and a Testing act subclass?
public abstract class Action
{
public virtual Project Project { get; set; }
}
public class CodingAction : Action {}
public class TestingAction : Action {}
public class ActionMap : ClassMap<Action>
{
public ActionMap()
{
DiscriminateSubClassesOnColumn("type")
.SubClass<CodingAction>(subclass => { })
.SubClass<TestingAction>(subclass => { });
}
}
that would make your schema:
create table Action (
Id int,
Project_id int,
type varchar(200)
)
create table Project (
Id int
)
Where the Action table has an additional type column that specifies which
class the instance is of. So instead of having to deal with multiple tables
for your triple, you could just have it mapped like so:
public Triple()
{
References(x => x.Project);
References(x => x.Coding);
References(x => x.Testing);
}
Where both Coding and Testing are referencing the Action table, rather than
specific TestAction or CodingAction tables. How does that sound?
If you're unsure about what's being mapped here, have a look at
Inheritance<http://www.nhforge.org/doc/nh/en/index.html#inheritance>
in
the NHibernate docs. I've suggested a Table per class hierarchy.
On Mon, Feb 16, 2009 at 7:57 AM, Guido Ziliotti <[email protected]>wrote:
>
> Maybe this example is not that intresting, anyway the main problem
> underling the sample is:
>
> how can I reference a unique key in the referenced table instead of
> the primary key of the referenced table?
>
>
>
> On Fri, Feb 13, 2009 at 4:54 PM, Guido Ziliotti
> <[email protected]> wrote:
> > I would like to ask how to map the sql script attacched to this mail.
> > Thwe script is for MSSQL. This is the piicture -a bit strange, but not
> too much.
> >
> > Entity:
> >
> > Prioject - Table prj, represnts a software pproject.
> > Action - A step to develop the porject. So the project is it's parent
> object
> >
> > But there are two kind of actions
> >
> > Coding - Table act_coding (action_id+project_id)
> > Testing - Table act_testing (action_id+project_id
> >
> > Now the ternary relation. Coding actions and testing actions may be
> related.
> > The relation is many to many but it has to happen inside the scope of a
> Common
> > Parent Project.
> >
> > So this is defined by the "triple" table which is composed by
> >
> > poject, coding, testing
> >
> > and project +coding must find a match in Coding Table, project + testing
> must
> > find a match in testing Table. This is a way to express the fact there is
> > indeed acommon project for the two actions.
> > By the way this is why project_id is not in The common base table Act. I
> had to
> > move it down to enable the foreign key form triple.
> >
> >
> > I would like to build suche tables with Fluent Nhibernate, or at least to
> map
> > them.
> >
> > Thanks.
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---