Nhibernate foreign key for foreign key mapping?

I have Staff object and e SecuredPage and the properties are below

Staff

ID First Name Last Name Level //SecuredPage.RoleId

SecuredPage

PageId RoleId // Staff.Level

I want to have a SecuredPage collection on the Person entity, so it is one-to-many, but I couldn't figure out how to handle it when mapping.

Staff.hbm.xml

<bag name="SecuredPages"  lazy="true" inverse="false" cascade="none">
      <key column="RoleId" />
      <many-to-many class="RealEstate.Core.Domain.SecuredPage,RealEstate.Core" />
</bag>

      

with code above Nhibernate gets all records from SecuredPage table where

SecuredPage.RoleId = Staff.id

      

But I want him to be

SecurePage.RoleId = Staff.StaffLevel

      

I haven't created an Entity role for some reason, so I'm just trying to get the secure pages for the Personnel based on its Level (Roles)

Hope I can tell you about my problem. I checked the Nhibernate manual, read all about collection mappings but I couldn't figure it out.

thank

+1


source to share


1 answer


I think the problem is that this is not very much for many. It is actually an expression of a many-to-many relationship.

I know this doesn't sound like what you wanted to hear (as you said, you didn't create a Role object), but you might want to do it for your own sake.

Is there a Role table that will act as a cross-reference between the two tables you provided?



If not, you must do one and it will help fix the problem. If so, you might think that the relationship between employees and roles is direct, and that employees and SecuredPages are indirect (via the roles that are there).

EDIT: Can you tell us why you didn't create a Role object? This can help us clarify.

+1


source







All Articles