c# - Fluent NHibernate Many-to-many mapping with auto-generated pk instead of composite key -


I am working on .NET in a RoleProvider, using Fluent NIBnet to map tables to Oracle 9.2 database I am doing

The problem is that users and roles connecting multiple-to-many tables use a primary key that is generated from a sequence, which is in contrast to the overall key. I can not really convert it, because I'm writing to implement it in a larger current system.

Here's my usermap:

  public usermap () {this.Table ("USR"); HasMany (x = & gt; x.Memberships) .Cascade.All () ("Member"). Inverted (). LazyLoad (); HasManyToMany (x = & gt; x.Roles). ("USR_ROLE") .Cascade.SaveUpdate () .ParentKeyColumn ("USR_ID") ChildKeyColumn ("ROLE_ID") .Not.LazyLoad (); }  

and my RoleMap:

  Public RoleMap () {this.Table ("ROLE"); Map (x = & gt; x.Description). Columns ("ROLE_NAME"); Map (x = & gt; x. Comment). Columns ("ROLA_COMMENT"); HasManyToMany (x = & gt; x.Users). Table ("USR_OLLE"). Parental column ("ROLE_ID"). Children's Column ("USR_ID") Inverted (); }  

However, this is giving me the error:

Type 'FluentNHibernate.Cfg.FluentConfigurationException' in the assembly 'FluentNHibernate, version = 1.0.0.593 , Culture = neutral, public-token = 8aa435e3cb308880 'has not been marked as serialable.

Is there any easy way to allow this HasMayToMany to use my PersistentObjectMap extension? I am thinking that I may have to add a conference to this many-to-many relationships, but I do not know where it will start, because I have just recently started using NHibernate and Fluent NHibernate

I am working on this problem for a while and I can not find any solution, any help will be very appreciable. Thank you.

Edit: I think I have found a potential solution here:

I will try the above method to create a unit and create a square Post the map and your findings for the linking table.

Edit 2: I have created a linking unit described in the blog post above and downloaded the latest binaries (1.0.0.623).
This showed me that this problem was trying to establish lazy load and to add roles to the user object in an entirely new session.

I have modified the code to move OpenSession in the initial order of the HTTP module. After doing so, I changed my data access code open session with wrapping in an experiment statement, which stops at the end of the session, to get the current session and to wrap the transaction in just one experiment statement .

It seems that a big part of my problem has been solved, but now I am getting an error which says "the collection can not be included" in the USR_ROLE table and I am thinking The code above should work with UserRoleMap, as described:

  public UserRoleMap () {this.Table ("USR_ROLE"); / * Map audit field ID, date / user created, updated date / user * / this.PersistentObjectMap ("USR_ROLE"); / * Link to these tables / references (x = & gt; x.Role). Columns ("ROLE_ID"); Reference (x = & gt; x.User). Column ("USR_ID"); }  

From the documentation of hibernation for many-to-many relationships, suggesting to create an object to maintain one-to-many / many-to-one like ERD get. I'm sure it would be very easy with traditional naming standards, but I have to be with some brief and weird (and not always correctly implemented) conventions.

To fix this, I created an entity, mapping, and repository for UserRole. And, instead of HasMany, several mappings in user and role units, I have HasMany mapping. It's a little weird, because I now have:

IList & lt; UserRole & gt; Get UserRoles { Protected Set;}

and IList & lt; Role & gt; Roles {{Return UserRoles}. Select (U = & gt; U.Rol) .Oolist (); }}

This works, however, I'm not 100% sure why it works and HasManyToMany do not.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -