Get an Entity Object with its child Entity with a condition (using Dynamic Linq)

亡梦爱人 提交于 2019-12-06 10:24:45

I figured out how Dynamic Expression API works. As I said I am new to these technologies, I am still learning things.

I had to achieve - c.CPNDocs.Where(d => d.L_STAT==true).Count()

I thought we have to write an expression in string and Dynamic Expression API will parse it to a real Expression, But I was wrong. we actually have to tell Parse method of Dynamic Expression API that what we want to do.

So I replaced c.CPNDocs.Count() in

Expression expression = System.Linq.Dynamic.DynamicExpression.Parse(null, "c.CPNDocs.Count()", paramExSymbols);

with c.CPNDocs.Where(L_STAT==true).Count(). Note the Where clause, It does not has LAMBDA Expression instead only a condition. Parse method will smartly understand what I am trying to do and convert it to an Expression with a dynamic reference and generate an Expression exactly same as what I was looking for -

c.CPNDocs.Where(Param_0 => (Param_0.L_STAT == True)).Count()

Where Param_0 is a Dynamic reference created for CPNDoc(an Record instance in CPNDocs). So final result I got what I was looking for.

Xmojmr, you last answer was the answer for this question too. Thanks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!