Maybe I've misunderstood, but isn't this scenario a self referencing many-to-many?
My guess is that you want something like this:
HasManyToMany<User>(x => x.Sponsors)
.Table("UserSponsor")
.ParentKeyColumn("UserId")
.ChildKeyColumn("SponsorId")
.AsBag();
On Wed, Jan 13, 2010 at 6:35 AM, TheNephalim <[email protected]>wrote:
> Hello,
>
> I'm a little confused about how to resolve this situation.
>
> I have two tables: User and UserSponsor. User is a table of users
> for our site. A user can have multiple sponsors. The UserSponsor
> table has two foreign keys UserId and SponsorId. SponsorId actually
> points back to the User table since a sponsor is a user on the site.
>
> The mapping for User is included below. The code actually compiles
> and runs, but the Sponsors property throws an ADOException error
> because it tries to include SponsorId at the top of the query, which
> is also included below.
>
> Any assistance that you can offer would be greatly appreciated.
>
> -Robert Eberhart
>
> public UserMap() {
> Table("SystemUser");
> Id(x => x.Id, "UserId");
> Map(x => x.FirstName, "UserFirstName");
> Map(x => x.MiddleName, "UserMiddleName");
> Map(x => x.LastName, "UserLastName");
> Map(x => x.UserName, "UserName");
> Map(x => x.UserApprovedYn, "UserApprovedYn");
> Map(x => x.UserLoginEnabledYn, "UserLoginEnabledYn");
> Map(x => x.Title, "UserTitle");
> Map(x => x.Email, "UserEmail");
> Map(x => x.ConfirmationCode, "ConfirmationNumber");
> Map(x => x.ConfirmationCodeApplied, "ApplicationDate");
> HasMany<User>(x => x.Sponsors)
> .Table("UserSponsor")
> .KeyColumn("SponsorId")
> .Where("UserId = :id")
> .AsBag();
> HasMany<PkiCertificate>(x => x.PkiCertificates)
> .Table("Certificates")
> .KeyColumn("SystemUserId")
> .Cascade.All().Inverse()
> .AsBag();
> HasMany<Phone>(x => x.PhoneNumbers)
> .Table("Phone")
> .KeyColumn("UserId")
> .Cascade.All().Inverse()
> .AsBag();
> JoinedSubClass<GovernmentUser>("UserId", m =>
> {
> m.References<GovernmentBuilding>(c => c.Building,
> "UserBldgId");
> m.Map(c => c.Room, "UserBldgRoom");
> m.References<GovernmentGrade>(c => c.Grade,
> "UserGradeId");
> });
> JoinedSubClass<NonGovernmentUser>("UserId", m => { });
> }
>
> SELECT sponsors0_.SponsorId as SponsorId1_, sponsors0_.UserId as
> UserId1_, sponsors0_.UserId as UserId0_0_, sponsors0_.UserFirstName as
> UserFirs2_0_0_, sponsors0_.UserMiddleName as UserMidd3_0_0_,
> sponsors0_.UserLastName as UserLast4_0_0_, sponsors0_.UserName as
> UserName0_0_, sponsors0_.UserApprovedYn as UserAppr6_0_0_,
> sponsors0_.UserLoginEnabledYn as UserLogi7_0_0_, sponsors0_.UserTitle
> as UserTitle0_0_, sponsors0_.UserEmail as UserEmail0_0_,
> sponsors0_.ConfirmationNumber as Confirm10_0_0_,
> sponsors0_.ApplicationDate as Applica11_0_0_,
> sponsors0_1_.UserBldgRoom as UserBldg2_1_0_, sponsors0_1_.UserBldgId
> as UserBldgId1_0_, sponsors0_1_.UserGradeId as UserGrad4_1_0_, case
> when sponsors0_1_.UserId is not null then 1 when sponsors0_2_.UserId
> is not null then 2 when sponsors0_.UserId is not null then 0 end as
> clazz_0_ FROM SystemUser sponsors0_ left outer join GovernmentUser
> sponsors0_1_ on sponsors0_.UserId=sponsors0_1_.UserId left outer join
> NonGovernmentUser sponsors0_2_ on
> sponsors0_.UserId=sponsors0_2_.UserId WHERE (sponsors0_.UserId = :id)
> and sponsors0_.SponsorId=?
>
>
> --
> 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]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>
>
>
-- 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.
