EntityFramework.Extended 实现Linq 动态查询和动态条件
找了很久的的关于EF 实现动态查询及条件,最后发现使用EntityFramework.Extended最为简单。
1. 引用EntityFramework.Extended (自己在Nuget下载)
using EntityFramework.Extensions;
using System.Linq.Dynamic;
2. 代码如下:
ERPContent erp = new ERPContent(); string s = "new ( state_key , state_name , act01, act02)"; string w = "state_key==1001 && act01 == true"; var lll = (from mst in erp.StateMsts join dt in erp.States on mst.state_key equals dt.state_key select new { mst.state_key,mst.state_des, mst.state_name, act01=mst.isactive , dt.state_value, act02= dt.isactive } ).Select(s).Where(w);