0

I'm using the Sharp-Architecture framework and I have an entity that looks like this:

public class BaanAlternateItemKey : ValueObject
{
    public virtual string ItemId { get; protected set; }

    public virtual string AlternateItemId { get; protected set; }
}

public class BaanAlternateItem : EntityWithTypedId<BaanAlternateItemKey>, IAlternateItem
{
    #region IAlternateItem Members

    public virtual IItem Item { get; protected set; }

    public virtual int Priority { get; protected set; }

    public virtual DateTime ExpirationDate { get; protected set; }

    #endregion
}

I have an auto mapping override that looks like this:

public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
    public void Override(AutoMapping<BaanAlternateItem> mapping)
    {
        mapping.ReadOnly();

        mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");

        mapping.CompositeId<BaanAlternateItemKey>(x => x.Id)
            .KeyProperty(x => x.ItemId, "ITEM_ID")
            .KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");

        mapping.References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
    }
}

I'm getting this exception:

----> NHibernate.MappingException : Could not determine type for: iPFS.Core.Baan.BaanAlternateItemKey, iPFS.Core, Version=0.0.4154.21888, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(Id)

I have no idea what I'm doing wrong. Any suggestions?

UPDATE: If I map this using fluent mapping it works fine:

public class BaanAlternateItemMap : ClassMap<BaanAlternateItem>
{
    public BaanAlternateItemMap()
    {
        ReadOnly();

        Table("VIEW_BAAN_ALTERNATE_ITEMS");

        CompositeId<BaanAlternateItemKey>(x => x.Id)
            .KeyProperty(x => x.ItemId, "ITEM_ID")
            .KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");

        Map(x => x.Priority, "PRIORITY");
        Map(x => x.ExpirationDate, "EXPIRATION_DATE").CustomType("Timestamp");

        References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
    }
}
Jeff B
  • 337
  • 1
  • 3
  • 10

2 Answers2

0

Is that shouldn't be that?:

public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
public void Override(AutoMapping<BaanAlternateItem> mapping)
{
    mapping.ReadOnly();

    mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");

    mapping.CompositeId<BaanAlternateItem>(x => x.Id) //are you mapping BaanAlternateItem right?
        .KeyProperty(x => x.ItemId, "ITEM_ID")
        .KeyProperty(x => x.AlternateItemId, "ALT_ITEM_ID");

    mapping.References<BaanItem>(x => x.Item, "ALT_ITEM_ID");
}
}

This error says that the mapping engine have no idea about any map for type BaanAlternateItemKey. So make sure that you have map for it.

Dariusz
  • 15,573
  • 9
  • 52
  • 68
  • Shouldn't the type be picked up by the CompositeId mapping statement? It works fine when I do it that way using fluent mappings. I don't believe that is the problem. Maybe I found another automapping bug? – Jeff B May 18 '11 at 14:30
0

I believe you'll want to convert the KeyProperty mapping for AlternateItemId to a KeyReference and then remove the References mapping as shown below. This assumes the Item has been mapped also and it has an Id property designated that matches the ALT_ITEM_ID value.

public class BaanAlternateItemAutoMappingOverride : IAutoMappingOverride<BaanAlternateItem>
{
    public void Override(AutoMapping<BaanAlternateItem> mapping)
    {
        mapping.ReadOnly();

        mapping.Table("VIEW_BAAN_ALTERNATE_ITEMS");

        mapping.CompositeId<BaanAlternateItem>(x => x.Id) //are you mapping BaanAlternateItem right?
            .KeyProperty(x => x.ItemId, "ITEM_ID")
            .KeyReference(x => x.Item, "ALT_ITEM_ID");
    }
}
Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • I'm not sure that is it. I updated my original question to show my current fluent mapping, which works fine. The Id property is of type BaanAlternateItemKey and is simply made up of the keys and not references. I suppose I could do as you suggest, but I don't believe it would make any difference. I could be wrong of course . . . I'll give a few things a try. – Jeff B May 18 '11 at 14:43