Here are my Fluent mappings (simplified to only include the necessary
pieces):
public class UserMap : ClassMap<User>
{
public UserMap()
{
Table("Users");
Id(x => x.UserId)
.GeneratedBy.Identity();
HasManyToMany(x => x.Networks)
.AsSet()
.Access.PascalCaseField(Prefix.Underscore)
.Table("UserNetworks")
.Inverse()
.ParentKeyColumn("UserId")
.ChildKeyColumn("NetworkId")
.Fetch.Select()
.AsSet()
.Cascade.SaveUpdate();
}
}
public class NetworkMap : ClassMap<Network>
{
public NetworkMap()
{
Table("Networks");
Id(x => x.NetworkId)
.GeneratedBy.Identity();
HasManyToMany(x => x.Users)
.Access.PascalCaseField(Prefix.Underscore)
.Table("UserNetworks")
.ParentKeyColumn("NetworkId")
.ChildKeyColumn("UserId")
.Fetch.Select()
.AsSet()
.Cascade.SaveUpdate();
}
}
On May 2, 3:00 pm, John Davidson <[email protected]> wrote:
> If you provide your mappings then I can give you a proper example. Without
> mappings the idea is to create a criteria to return the Networks object and
> alias the UserNetworksXref and then select where UserNetworksXref.User =
> User
>
> John Davidson
>
>
>
>
>
> On Sun, May 2, 2010 at 4:51 PM, Kevin Pang <[email protected]> wrote:
> > I have two tables, Users and Networks, with a many-to-many
> > relationship table UserNetworks to indicate which Users are in which
> > Networks. I do not have a UserNetwork class to correspond to the
> > UserNetworks table.
>
> > How can I construct a query using the Criteria API to retrieve all
> > Networks that belong to a User?
>
> > I'm aware that I can simply load up a User first, then traverse over
> > its Networks property, but I was wondering how you would do it if you
> > wanted to do it via a query instead.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]
> > >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" 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
> athttp://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en.