Help Overriding two properties mapped to the same type

Original Post Jeff Vandenberg's Avatar

Jeff Vandenberg

29 May, 2010 05:08 PM via web

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

  1. Support Staff 2 Posted by James Gregory on 29 May, 2010 06:34 PM

    James Gregory's Avatar

    What is Thickness? If it's not an enum, you'll need to create an IUserType for it.

  2. 3 Posted by Jeff Vandenberg on 29 May, 2010 08:10 PM

    Jeff Vandenberg's Avatar

    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.

  3. Support Staff 4 Posted by Paul Batum on 30 May, 2010 04:56 AM

    Paul Batum's Avatar

    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.

  4. 5 Posted by jeff vandenberg on 30 May, 2010 07:09 AM

    jeff vandenberg's Avatar

    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.

        public void Override(AutoMapping<ProjectAuditedEntity> mapping)
        {
            mapping.Map(x => x.CreatedBy).Column("CreatedBy").Nullable();
            mapping.Map(x => x.UpdatedBy).Column("UpdatedBy").Nullable();
            mapping.Version(m => m.Version);
        }
    

    If this is something I have missed in the documentation I would appreciate a pointer in the right direction.

  5. Support Staff 6 Posted by Paul Batum on 30 May, 2010 09:10 AM

    Paul Batum's Avatar

    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

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the number before twelve?

    Recent Discussions

    05 Jul, 2010 10:29 PM
    05 Jul, 2010 12:45 PM
    05 Jul, 2010 12:42 PM
    05 Jul, 2010 12:17 PM
    05 Jul, 2010 12:12 PM

     

    03 Jul, 2010 12:26 AM
    02 Jul, 2010 02:17 PM
    02 Jul, 2010 08:18 AM
    02 Jul, 2010 12:20 AM
    01 Jul, 2010 10:14 PM