2010-09-25 77 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」。

如果有人能告訴我映射這個的正確方法,我將不勝感激。謝謝

回答