ActiveRecord Many-To-Many Duplicate Records Fix

I have been trying to figure out how to properly model a many-to-many relationship in ActiveRecord so that it would make both of the columns in the associative table primary keys and not allow duplicates in the collection. I have original implement the HasAndBelongsToMany using an IList which allows duplicates so ActiveRecord does not generate the associative table with both columns as primary keys. To get around this I had to use the ISet collection that is part of the Iesi.Collection dll that comes with nHibernate. Sets does not allow duplicates and when ActiveRecords generates the db schema this causes it to make both columns in the associative table as primary keys. Even if you add a duplicate record into the Set collection, it does not get added to the database.

I ended up using a HashedSet since it was the fastest for bigger collections. To figure out how to implement an ISet collection, I read thru the following codeproject article, http://www.codeproject.com/csharp/sets.asp


Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 5. 2009 11:54 AM