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);
}
}
除了询问之外,一切正常。当我尝试做:
session.Linq<Transaction>().Where(t => t.Type == TransactionTypes.Event).ToList();
它抛出错误“类型不匹配”
NHibernate.Criterion.SimpleExpression
System.Int32
Entities.TransactionTypes
".