开发者

NHibernate ICritery add IEnumerable<int>?

I'm fairly new to NHibernate and I'm trying to modify a criteria that currently takes a single integer, using something like (simplifi开发者_如何转开发ed):

int attributeId = 5;
Attribute attributeAlias = null;

var criteria = DetachedCriteria<Asset>.Create(() => attributeAlias)
.Add(() => attributeAlias.Id == attributeId )

But I want to change it to allow passing in a list of attributeIds, similar to this.

IEnumerable<int> attributeIds = new List<int> ( ) { 5, 6, 7, 8 };

I have not yet been able to figure out how to update the criteria to allow a list. Does anyone have any references on doing this?


int[] attributeIds = { 5, 6, 7, 8 };

ICriteria criteria = Session.CreateCriteria();
criteria.Add(Expression.In("Id", attributeIds)); //this is the important part
criteria.List();

Update: From what Zenox also contributed:

ICriteria criteria = Session.CreateCriteria();
criteria.Add(Restrictions.In ( LambdaProjection.Property ( ( ) => attributeAlias.Id ), attributeIds .ToArray ( ) ));
criteria.List();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜