无法弄清楚多用户属性'用户'的另一面应该是什么

时间:2010-02-11 14:43:46

标签: nhibernate fluent-nhibernate automapping

我的域自动映射工作正常但现在当我更新我的NHibernate堆栈时,我在Session Factory构建配置时遇到映射异常:

  

“无法弄清楚对方是什么   众多房产'用户'   应该是。“

在多对多地图上抛出异常

整个堆栈跟踪就是这个:

  

在   FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()   在
  C:\ hornget.horn \ ORM \ fluentnhibernate \工作-2.1的\ src \ FluentNHibernate \ CFG \ FluentConfiguration.cs:行   119在    WebApplication1.NHibernateManager.SessionFactoryManager.BuildConfiguration(AutoPersistenceModel
  persistanceModel)在   C:\ WebProgramming \项目\ WebApplication1 \ WebApplication1 \ NHibernateManager \ SessionFactoryManager.cs:行   116在   WebApplication1.NHibernateManager.SessionFactoryManager.GetSessionFactory()   在
  C:\ WebProgramming \项目\ WebApplication1 \ WebApplication1 \ NHibernateManager \ SessionFactoryManager.cs:行   71在   WebApplication1.NHibernateManager.SessionManager.CloseSession()   在
  C:\ WebProgramming \项目\ WebApplication1 \ WebApplication1 \ NHibernateManager \ SessionManager.cs:行   47在   WebApplication1.Global.Application_EndRequest(Object sender,EventArgs e)在   C:\ WebProgramming \项目\ WebApplication1 \ WebApplication1 \的Global.asax.cs:行
  36在   System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  在
  System.Web.HttpApplication.ExecuteStep(IExecutionStep   步,布尔&已完成(同步)

问题是如何使用自动化正确处理多对多关系   注意:在更新NHibernate / FluentNHibernate堆栈之前,映射工作正常...

相关定义粘贴在下面:

Domain类(在Dll 1中):

public class User : Entity  
{  
// ... removed properties  

    public virtual IList<Role> Roles { get; protected set; }//has many  

// ...  removed methods   
}

public class Role : Entity
{
// ... removed properties  

    public virtual IList<User> Users { get; protected set; }//has many

// ... removed methods  
}

实体类(在DLL 2中):

/// <summary>
/// Base Entity deffinition
/// </summary>
public abstract class Entity : IEquatable<Entity>
{
    private int _Id = 0;
    public virtual int Id { get { return _Id; } }

    //... removed methods  
}

公约:

public class PrimaryKeyConvention : IIdConvention
{
    public void Apply(IIdentityInstance instance)
    {
        instance.Column(instance.EntityType.Name + "Id");
        instance.GeneratedBy.HiLo("100");
        instance.Access.ReadOnlyPropertyThroughPascalCaseField(PascalCasePrefix.Underscore);

    }
}


public class ClassConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Table(Inflector.Pluralize(instance.EntityType.Name));
        instance.LazyLoad();
        instance.Cache.NonStrictReadWrite();
    }
}  

多对多公约:

public class ManyToManyConvention : IHasManyToManyConvention
{
    public void Apply(IManyToManyCollectionInstance instance)
    {
        if (instance.OtherSide == null)
        {
            instance.Table(
                string.Format(
                    "{0}To{1}",
                    Inflector.Pluralize(instance.EntityType.Name),
                    Inflector.Pluralize(instance.ChildType.Name)));
            instance.Cascade.AllDeleteOrphan();
        }
        else
        {
            instance.Inverse();
        }
    }

}

型号:

 var persistanceModel = AutoMap.AssemblyOf<DataModelPaceholder>()
        .AddEntityAssembly(typeof(Entity).Assembly)
        .Conventions.AddFromAssemblyOf<ClassConvention>()
        .UseOverridesFromAssemblyOf<DataModelPaceholder>()
        .Setup(s =>
        {
            s.SubclassStrategy = t => SubclassStrategy.JoinedSubclass;
            s.IsComponentType = type => type == typeof(MoneyComponent);
        })
        .IgnoreBase<Entity>()
        .IgnoreBase<EntityAudit>()
        //.IncludeBase<Product>()
        .Where
        (
            type => typeof(Entity).IsAssignableFrom(type) && !type.IsAbstract
        );

1 个答案:

答案 0 :(得分:0)

根据AutoMap默认约定,您是否有一个名为UsersToRoles的联结表,其中包含相应命名的列?例如User_id,Role_id?