簡體   English   中英

nhibernate查詢使用條件作為值類型列表

[英]nhibernate query using criteria for list of value type

類包含整數列表: ICollection<int> CategoryEnum

我如何為此創建查詢條件?

我試過了:

List<int> postedCategories = new List<int>{ 1 };
int category = 0;

q.JoinAlias(p => p.CategoryEnum, () => category)
 .AndRestrictionOn(x => category)
   .IsIn(postedCategories);

但是我在(1)中得到一個SQL查詢WHERE 0

我對對象的集合沒有任何問題,它可以工作,但對int的收集不起作用。

這是我的映射的一部分:

<set name="CategoryEnum" table="CategoriesEnum">
  <key column="Id"></key>
  <element column="CategoryId" type="int"></element>
</set>

檢查以下問答:

您會發現,我們可以使用關鍵字".elements"訪問element

Restrictions.In("category.elements", postedCategories)

查詢結束:

q.JoinAlias(p => p.CategoryEnum, () => category)
 .Where(Restrictions.In("category.elements", postedCategories))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM