Reputation: 1383
I copied example from Fluent NHibernate GitHub documentation for automapping and it doesn't work in my ASP.NET MVC 4 app.
public class Product
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual decimal Price { get; set; }
}
public class Shelf
{
public virtual int Id { get; set; }
public virtual IList<Product> Products { get; set; }
public Shelf()
{
Products = new List<Product>();
}
}
Are models. When I add
.Mappings(m => m.AutoMappings
.Add(AutoMap.AssemblyOf<Product>()))
to my configuration I get error No parameterless constructor defined for this object.
. Without that, my session works fine and also with mapping defined by me one by one, everything works. Just automapping doesn't work. What's the problem?
Upvotes: 2
Views: 607
Reputation: 123861
The issue is that in the Assembly containing the Product
, could be some object/entity, with such a "missing parameterless constructor" (some helper object). You have to be more specific, try to use the .Where()
to narrow the set of auto-mapped objects/entities
.Mappings(m =>
m.AutoMappings
.Add(AutoMap.AssemblyOf<Product>()
.Where(t => t.Namespace ==...
...or something like that. Just be precise what should be auto-mapped.
Upvotes: 1