c# - 找不到字段 : 'NHibernate.NHibernateUtil.String'

标签 c# nhibernate fluent-nhibernate nhibernate-mapping saga

我正在尝试配置 NHibernateid="NHibernate"version="4.0.0.4000"targetFramework="net451" 和 fluent 包 id="FluentNHibernate"version="2.0.1.0"targetFramework="net451"。以下代码:

var sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory)
.Mappings(m =>
{
    m.FluentMappings
    .AddFromAssemblyOf<ExampleSagaMap>();
)
.ExposeConfiguration(cfg =>
{
    chemaExport = new SchemaExport(cfg);
})
.BuildSessionFactory();

map 代码:

public ExampleSagaMap()
{
    Not.LazyLoad();

    Id(x => x.CorrelationId).GeneratedBy.Assigned();

    Map(x => x.CurrentState)
        .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
        .CustomType<StateMachineUserType>();

    Map(x => x.MessagesReceived);
    Map(x => x.MessagesSent);
}

错误:

An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

Inner error: {"Field not found: 'NHibernate.NHibernateUtil.String'."}

有人可以帮忙吗? 谢谢

最佳答案

在我的例子中,我收到此错误是因为我使用引用 NHibernateUtil.String.SqlTypeIUserType 实现了自定义枚举类型。

解决方案是改用新的 SqlTypeFactory

/* Used by NHibernate to cast between string and type-safe-enum */
public class MyCustomEnumType : IUserType
{

    ...

    public SqlType[] SqlTypes
    {
        get { 
            return new[] {                   
                // not working for NHibernate 4.1
                //NHibernateUtil.String.SqlType 
                SqlTypeFactory.GetString(200)
            }; 
        }
    }        

    ...
}

关于c# - 找不到字段 : 'NHibernate.NHibernateUtil.String' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219619/

相关文章:

nhibernate - 使用 NHibernate 在插入时数据库生成日期

c# - NHibernate 的独立 Hello World 类型示例

c# - 如何使用 Nhibernate 多次内连接同一张表

exception-handling - 流畅的 NHibernate : Debugging FluentConfigurationException

c# - 中止请求时 IIS/C# 中会发生什么

c# - 尝试使用 Python 从工作 C# 代码生成 RSA 签名

c# - 使用 nHibernate 通过子集合限制 QueryOver

nhibernate - 如何在NHibernate中与null建立一对一的关系?

c# - "The SMTP host was not specified."- 但它是指定的?

C# 如何正确地对遵循装饰器模式的类进行单元测试?