Help Overriding two properties mapped to the same type
Ok, so this is causing me to pull out my air and I am trying to figure out what mistake I am making.
Object Product
public virtual string Name
public virtual Thickness EndThickness
public virtual Thickness SideThickness
... other properties
I am using automapping and have an overrider created for the Product class
public void Override(AutoMapping<Product> mapping)
{
mapping.Map(m => m.EndThickness).Column("EndThickness").Nullable();
mapping.Map(m => m.SideThickness).Column("SideThickness").Nullable();
}
Thickness is just a simple class. Id, Name, and DisplayOrder for a select list.
It compiles fine, but when I try to load the web application I see the following error:
Could not determine type for: Project.Core.ProductComponent.Thickness, Project.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(EndThickness)
What am I missing? I have a similar override to map the CreatedBy and UpdatedBy Id columns to the relevant User records for Audited objects.
I have done something similar for
Support Staff 2 Posted by James Gregory on 29 May, 2010 06:34 PM
What is
Thickness
? If it's not an enum, you'll need to create anIUserType
for it.3 Posted by Jeff Vandenberg on 29 May, 2010 08:10 PM
Thickness is a POCO. It's automapped to a backing table Thicknesses in the DB. It's just meant to be a table to feed two drop down lists on the the form.
None of the rest of the types that the Product implement have interfaces and all seem to work.
Support Staff 4 Posted by Paul Batum on 30 May, 2010 04:56 AM
It sounds like a Product references two Thickness records, as in the product
table has two foreign keys to the thickness table. If so you want:
public void Override(AutoMapping<Product> mapping)
{
mapping.References(m =>
m.EndThickness).Column("EndThickness").Nullable();
mapping.References(m =>
m.SideThickness).Column("SideThickness").Nullable();
}
This is assuming that your foreign key columns are called EndThickness and
SideThickness.
Let me know if I'm on the right track - if not, you should provide your
schema.
5 Posted by jeff vandenberg on 30 May, 2010 07:09 AM
Paul,
Thanks! Changing it from an Add to a References got it to work, or at least load. I will do further testing when it's not 2am my time.
I have a question related to this then. What is the difference between References() and Add()? I have a similar construct to the above but it uses Map() what User created or updated the entity.
If this is something I have missed in the documentation I would appreciate a pointer in the right direction.
Support Staff 6 Posted by Paul Batum on 30 May, 2010 09:10 AM
By Add() I presume you mean Map(). Basically Map is for simple properties.
References is for a many-to-one relationship. The getting started guide
covers this:
http://wiki.fluentnhibernate.org/Getting_started