singleordefault(where) 条件不支持动态
所以想要达到目标,就需要转换思路,把where在前面调用,然后再接,代码如下
public TResult GetSingle<T, TResult>(Expression<Func<T, bool>> exWhere, Expression<Func<T, TResult>> selector) where T : class { using (SysDb<T> db = new SysDb<T>(strConn)) { return db.Set<T>().AsExpandable().Where(exWhere).Select(selector).SingleOrDefault(); } }
使用:
dynamic v_sysuser = basebll_Jyxt.GetSingle<V_SysUserAndBC, dynamic> (c => (c.UserCode == hdnUserCode && c.IsQYUser == true), c => new { c.SubSystemName });
ef linq select where dynamic singleordefault,布布扣,bubuko.com
ef linq select where dynamic singleordefault
原文:http://blog.csdn.net/laokaizzz/article/details/29381247