Fluent nhibernate Fluent NHibernat-使用LINQ查询枚举字段

Fluent nhibernate Fluent NHibernat-使用LINQ查询枚举字段,fluent-nhibernate,linq-to-nhibernate,Fluent Nhibernate,Linq To Nhibernate,我的应用程序具有以下数据库结构: Transactions: - TransactionID (PK, Identity, Int) - TypeID (FK, Int) - Amount (Decimal) TransactionTypes: - TypeID (PK, Identity, Int) - Type (NVarChar) 它们在我的应用程序中定义为: public class Transaction { public virtual int TransactionID

我的应用程序具有以下数据库结构:

Transactions:
- TransactionID (PK, Identity, Int)
- TypeID (FK, Int)
- Amount (Decimal)

TransactionTypes:
- TypeID (PK, Identity, Int)
- Type (NVarChar)
它们在我的应用程序中定义为:

public class Transaction
{
    public virtual int TransactionID { get; set; }
    public virtual TransactionTypes Type { get; set; }
    public virtual decimal Amount { get; set; }
}

public enum TransactionTypes
{
    Event = 1,
    Product = 2
}
使用以下映射:

public class TransactionMap : ClassMap<Transaction>
{
    public TransactionMap()
    {
        Table("Transactions");
        Id(x => x.TransactionID);
        Map(x => x.Type, "TypeID").CustomType<int>();
        Map(x => x.Amount);
    }
}
公共类事务映射:类映射
{
公共事务映射()
{
表(“交易”);
Id(x=>x.TransactionID);
映射(x=>x.Type,“TypeID”).CustomType();
Map(x=>x.Amount);
}
}
除了查询之外,一切都很好。当我尝试这样做时:

session.Linq<Transaction>().Where(t => t.Type == TransactionTypes.Event).ToList();
session.Linq().Where(t=>t.Type==TransactionTypes.Event).ToList();
它抛出错误“NHibernate.Criteria.SimpleExpression中的类型不匹配:类型预期类型
系统.Int32
,实际类型
实体.TransactionType


如果有人能告诉我正确的地图绘制方法,我将不胜感激。谢谢

在Fluent NHibernate中映射枚举的最佳方法是使用约定。请参阅以下两个线程以获取帮助: