2010-09-25 45 views
1

我的应用程序有以下的数据库结构:流利NHibernat - 查询枚举场与LINQ

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”。

如果有人能告诉我映射这个的正确方法,我将不胜感激。谢谢

回答