Linq - NHibernate - get all classes where the dictionary property contains one of the items from my list
I'm having a class foo like
foo
{
Dictionary<string, Blubb> blubbDict {get;set;}
Dictionary<Bar, string> barDict {get;set;}
}
Now i'd like to load all objects from the database where blubbDict containts a key "FooBar" and where barDict contains any objects Bar which i have loca开发者_运维技巧lly in a List barList.
What i got so far:
var fooQuery = from c in session.Query<Foo>()
where c.blubbDict.ContainsKey("FooBar")
select c;
which works so far. But what about my last condition. I'd like only the Foo objects where both conditions meet "FooBar" AND the key of barDict is in my local List.
Can anyone help me? I can't get my head around that problem.
Never tried to do it so I'm not absolutely sure Linq For NH supports it but you can try:
var fooQuery = session.Query<Foo>()
.Where(c => c.blubbDict.ContainsKey("FooBar"))
.Where(c => barList.Any(b => c.barDict.ContainsKey(b)));
精彩评论