Thx, I posted it over there now...

On 16 Jul., 11:51, James Gregory <[email protected]> wrote:
> Interesting, perhaps I'm wrong then. You're still better asking this over at
> nh-users.
>
>
>
> On Thu, Jul 16, 2009 at 10:44 AM, Darko Konrad <[email protected]> wrote:
>
> > Hi James,
>
> > there is no PK generated at all. That was the reason for my post.
> > Here is the generated SQL:
>
> > create table [SegmentGroup] (
> >  SegmentGroupId BIGINT IDENTITY NOT NULL,
> >   SegmentGroupName NVARCHAR(255) null,
> >   primary key (SegmentGroupId)
> > )
> > create table SegmentGroupSegments (
> >  SegmentGroupId BIGINT not null,
> >   SegmentId BIGINT not null
> > )
> > create table [Segment] (
> >  SegmentId BIGINT IDENTITY NOT NULL,
> >   SegmentName NVARCHAR(255) null,
> >   primary key (SegmentId)
> > )
>
> > and later the FKs:
> > alter table SegmentGroupSegments add constraint FK53B4C5B6C2AAA71A
> > foreign key (SegmentId) references [Segment]
> > alter table SegmentGroupSegments add constraint FK53B4C5B67B5AADE7
> > foreign key (SegmentGroupId) references [SegmentGroup]
>
> > This is, btw, what happens to ALL of my many-to-many relations.
>
> > thats it.
>
> > regards,
> > Darko
>
> > On 16 Jul., 11:05, James Gregory <[email protected]> wrote:
> > > What do you mean by "there is no PK" when you then say you don't want a
> > > surrogate key, is there a key or not?
> > > I'm pretty sure there's always a surrogate key on the many-to-many
> > tables,
> > > that's just how NH generates the schema. I've had a look in the XSD and I
> > > can't see any attributes to specify a unique constraint. You could maybe
> > use
> > > the check attribute on your collection, but I'm not sure it's for that
> > > purpose.
>
> > > On Thu, Jul 16, 2009 at 9:06 AM, Darko Konrad <[email protected]>
> > wrote:
>
> > > > Hi guys,
>
> > > > I have a many-to-many relationship which is implemented as
> > > > bidirectional.
>
> > > > public class SegmentGroup
> > > > {
> > > >    public virtual long Id { get; protected set; }
> > > >    public virtual string SegmentGroupName { get; set; }
> > > >    public virtual IList<Segment> Segments { get; set; }
> > > > }
>
> > > > and
>
> > > > public class Segment
> > > > {
> > > >    public virtual long Id { get; protected set; }
> > > >    public virtual string SegmentName { get; set; }
> > > >    public virtual IList<SegmentGroup> SegmentGroups { get; set; }
> > > > }
>
> > > > I am using the automapping feature with the following conventions:
>
> > > > ....
> > > >  .ForTypesThatDeriveFrom<SegmentGroup>(m1 => m1.HasManyToMany(x =>
> > > > x.Segments)
> > > >                                      .WithTableName
> > > > ("SegmentGroupSegments")
> > > >                                      .Cascade.All()
> > > >                                      .WithParentKeyColumn
> > > > ("SegmentGroupId")
> > > >                                      .WithChildKeyColumn
> > > > ("SegmentId"))
>
> > > > .ForTypesThatDeriveFrom<Segment>(m1 => m1.HasManyToMany(x =>
> > > > x.SegmentGroups)
> > > >                                      .WithTableName
> > > > ("SegmentGroupSegments")
> > > >                                      .Cascade.All()
> > > >                                      .Inverse()
> > > >                                      .WithParentKeyColumn
> > > > ("SegmentGroupId")
> > > >                                      .WithChildKeyColumn
> > > > ("SegmentId"))
> > > > ....
>
> > > > The tables are generated correctly, however there is no PK (combined,
> > > > don't want a surrogate PK)
> > > > in the link table. Is that so by design? If yes, how do I at least set
> > > > UNIQUE constraint on
> > > > the combination of the 2 FKs?
>
> > > > Here are the generated hbms:
>
> > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > > > access="">
> > > >  <class name="Fintexx.STAR.DataContract.SegmentGroup,
> > > > Fintexx.STAR.DataContract, Version=1.0.0.0, Culture=neutral,
> > > > PublicKeyToken=null" table="`SegmentGroup`" xmlns="urn:nhibernate-
> > > > mapping-2.2">
> > > >    <id name="Id" type="Int64" column="SegmentGroupId">
> > > >      <generator class="identity" />
> > > >    </id>
> > > >    <property name="SegmentGroupName" type="String">
> > > >      <column name="SegmentGroupName" />
> > > >    </property>
> > > >    <bag name="Segments" cascade="all" table="SegmentGroupSegments">
> > > >      <key column="SegmentGroupId" />
> > > >      <many-to-many column="SegmentId"
> > > > class="Fintexx.STAR.DataContract.Segment, Fintexx.STAR.DataContract,
> > > > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
> > > >    </bag>
> > > >  </class>
> > > > </hibernate-mapping>
>
> > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > > > access="">
> > > >  <class name="Fintexx.STAR.DataContract.Segment,
> > > > Fintexx.STAR.DataContract, Version=1.0.0.0, Culture=neutral,
> > > > PublicKeyToken=null" table="`Segment`" xmlns="urn:nhibernate-
> > > > mapping-2.2">
> > > >    <id name="Id" type="Int64" column="SegmentId">
> > > >      <generator class="identity" />
> > > >    </id>
> > > >    <property name="SegmentName" type="String">
> > > >      <column name="SegmentName" />
> > > >    </property>
> > > >    <bag name="SegmentGroups" cascade="all" inverse="true"
> > > > table="SegmentGroupSegments">
> > > >      <key column="SegmentId" />
> > > >      <many-to-many column="SegmentGroupId"
> > > > class="Fintexx.STAR.DataContract.SegmentGroup,
> > > > Fintexx.STAR.DataContract, Version=1.0.0.0, Culture=neutral,
> > > > PublicKeyToken=null" />
> > > >    </bag>
> > > >  </class>
> > > > </hibernate-mapping>
>
> > > > THX,
> > > > Darko
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to