开发者

Fluent NHibernate Mapping Components, one indexed, one not indexed

开发者 https://www.devze.com 2023-01-19 18:00 出处:网络
Am getting an error on VerifyTheMapping test: System.ApplicationException: For property \'ANonindexedComponent\'

Am getting an error on VerifyTheMapping test:

System.ApplicationException: For property 'ANonindexedComponent' expected 'Generic.TheDomain.NonindexedComponent' of type 'Generic.TheDomain.NonindexedComponent' but got '' of type 'Generic.TheDomain.NonindexedComponent' and System.ApplicationException: For property 'IndexedComponent' expected 'Generic.TheDomain.IndexedComponent' of type 'Generic.TheDomain.IndexedComponent' but got '' of type 'Generic.TheDomain.IndexedComponent'

given:

namespace Generic.TheDomain
{
    public class UseAIndexedComponent:DomainEntity<UseAIndexedComponent>
    {
        public virtual string NameTitle { get; private set; }
        public virtual IndexedComponent IndexedComponent { get; private set; }
    }

    public class UseANonindexedComponent:DomainEntity<UseANonindexedComponent>
    {
        public virtual string TitleName { get; private set; }
       开发者_运维问答 public virtual NonindexedComponent 
            ANonindexedComponent { get; private set; }
    }

    //we want this one to have a unique index on A B C
    public class IndexedComponent
    {
        public virtual string A { get; private set; }
        public virtual string B { get; private set; }
        public virtual string C { get; private set; }

        public IndexedComponent(){}
    }

    //no unique index on this one...
    public class NonindexedComponent : IndexedComponent
    {
        public NonindexedComponent(){}
    }
}

Fluent NHibernate mappings:

using FluentNHibernate.Mapping;
using Generic.TheDomain;

namespace Persistence.Mappings
{
    public class IndexedMap : ClassMap<UseAIndexedComponent>
    {
        public IndexedMap()
        {
            Table("IndexedComponent");
            Id(x => x.Id).GeneratedBy.GuidComb();
        Map(x => x.NameTitle);
        Component<IndexedComponent>(x => x.IndexedComponent);
    }
}

    public class NonIndexedMap : ClassMap<UseANonindexedComponent>
    {
        public NonIndexedMap()
        {
            Table("NonIndexedComponent");
            Id(x => x.Id).GeneratedBy.GuidComb();
            Map(x => x.TitleName);
            Component<NonindexedComponent>(x => x.ANonindexedComponent);
        }
    }

    public class IndexedComponentMap : ComponentMap<IndexedComponent>
    {
        public IndexedComponentMap()
        {
            Map(x => x.A).CustomSqlType("varchar(1)").UniqueKey("ABC");
            Map(x => x.B).CustomSqlType("varchar(1)").UniqueKey("ABC");
            Map(x => x.C).CustomSqlType("varchar(1)").UniqueKey("ABC");
        }
    }

    public class NonindexedComponentMap : ComponentMap<NonindexedComponent>
    {
        public NonindexedComponentMap()
        {
            Map(x => x.A).CustomSqlType("varchar(1)");
            Map(x => x.B).CustomSqlType("varchar(1)");
            Map(x => x.C).CustomSqlType("varchar(1)");
        }
    }
}

and the test:

[Test]
public void VerifyIndexedMapping()
{
new PersistenceSpecification<UseAIndexedComponent>(Session)
        .CheckProperty(c => c.NameTitle, "jack")
    .CheckProperty(x => x.IndexedComponent, new IndexedComponent())
        .VerifyTheMappings();
}

[Test]
public void VerifyNonIndexedMapping()
{
    new PersistenceSpecification<UseANonindexedComponent>(Session)
        .CheckProperty(c => c.TitleName, "jill")
        .CheckProperty(x => x.ANonindexedComponent, new NonindexedComponent())
        .VerifyTheMappings();
}


http://www.nhforge.org/doc/nh/en/index.html#persistent-classes-equalshashcode

0

精彩评论

暂无评论...
验证码 换一张
取 消