S#arp Architecture many-to-many mapping overrides not working

I have tried pretty much everything to get M:M mappings working in S#arp Architecture. Unfortunately the Northwind example project does not have a M:M override.

All worked fine in my project before converting to S#arp and its choice of Fluent NHibernate's Auto mapping. I like the auto-mapping, it's good, however the overrides do not seem to register.

It all seems to work in memory and in tests, however when committing data to a database nothing gets inserted into my M:M reference table.

If we take the simple sample of a Category can have many Products and a Product can be in many Categories we would have a table called CategoryProduct (I don't like pluralisation) that has columns Category_id and Product_id.

My Auto persistence model generates as such:

return AutoPersistenceModel .MapEntitiesFromAssemblyOf<Category>() .Where(GetAutoMappingFilter) .ConventionDiscovery.Setup(GetConventions()) .WithSetup(GetSetup()) .UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

Mapping override for Category looks like such:

public class CategoryMap : IAutoMappingOverride<Category> { public void Override(AutoMap<Category> mapping) { mapping.Id(x => x.Id, "Id") .WithUnsavedValue(0) .GeneratedBy.Identity(); mapping.Map(x => x.Name).WithLengthOf(50); mapping.Map(x => x.Depth); mapping.HasMany<Category>(x => x.Children) .Cascade.All() .KeyColumnNames.Add("Parent_id") .AsBag() .LazyLoad(); mapping.HasManyToMany<Posting>(x => x.Products) .WithTableName("CategoryProduct") .WithParentKeyColumn("Category_id") .WithChildKeyColumn("Product_id") .Cascade.All() .AsBag(); } }

And the Product has a mapping override as such:

public class ProductMap : IAutoMappingOverride<Product> { public void Override(AutoMap<Product> mapping) { mapping.Id(x => x.Id, "Id") .WithUnsavedValue(0) .GeneratedBy.Identity(); mapping.Map(x => x.Title).WithLengthOf(100); mapping.Map(x => x.Price); mapping.Map(x => x.Description).CustomSqlTypeIs("Text"); mapping.References(x => x.Category).Cascade.All(); mapping.HasMany<ProductImage>(x => x.Images).Inverse().Cascade.All().LazyLoad(); mapping.HasManyToMany<Category>(x => x.Categories) .WithTableName("CategoryProduct") .WithParentKeyColumn("Product_id") .WithChildKeyColumn("Category_id") .Inverse() .AsBag(); } }

I've tried many combinations of structuring the M:M mappings, but nothing works.

This article has suggestion to re-compile S#arp with update FHN, I tried this however the latest FHN code is vastly different to that used by S#arp it would seem. Fixed all the breaking conflicts but it still doesn't work.

Hopefully someone else has encountered and resolved M:M auto-mapping override problems with S#arp.


Managed to solve the issue, turned out to being a S#arp beginners error.

For ManyToMany data to be saved then the controller method need to have the [Transaction] attribute assigned to it.


  • Traversing a multi-dimensional array
  • How to filter many2one res.parner field in odoo
  • Meteor form state not being saved
  • Yiic Grid view always giving live is not a function
  • Getting selected item values in Datalist
  • Fill missing combinations in a dataframe
  • Change the cart item quantity for specific products in woocommerce
  • How can i clean temp tables on mysql
  • MSBuild add file to primary output
  • Visual Studio 2008 would not debug
  • How can I join lazy translation in Django?
  • How do I handle options in a packaged Chrome App?
  • Gradle Thrift Plugin by Example
  • How to debug charts package 'No module named 'plot' ' Error
  • How to write an RSpec test for Ryan Bates' helper from screencast #228?
  • How do I use multiple databases with JPA?
  • How to deal with xxx~HEAD after git merge?
  • How to update data in Redis and MySQL at the same time?
  • Event files in Google Tensorflow
  • Winform Designer Application
  • several hexbin plots on one PDF page in R
  • How to fix: The return type of an async method must be void, Task or Task [AppName]
  • How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?
  • Applying custom annotation advice to spring data jpa repository
  • MOC adding namespace to class names
  • C++ Boost ptr_map serialization error
  • javascript / jquery scope differences between jQuery.each and normal for loop?
  • Usage of local dart library
  • Why is it still possible to insert a foreign key that doesn't exist?
  • array_search() in Session Array
  • HighCharts - Show tooltip on column where value is 0 or null
  • triggering user space with kernel
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?