我想用参数更改 where 子句。示例我有 2 个字符串变量。
string searchText="John";
string userField="Name"//it can be ID,UserName or Email
我想根据“string userField="Name"/”更改用户属性(a.Name)
var a entities.Users
where a.Name==searchText //a.Name(Name) is declared in userField. It can be ID,UserName or Email
我的代码如下所示:
var users = new
{
total = 10,
page = page,
record = (entities.Users.Count()),
rows = (from user in entities.Users
select new
{
ID = user.ID,
Name = user.Name,
UserName = user.UserName,
UserType = user.Role.Name,
Email = user.Email,
CreatedDate = user.CreatedDate,
UpdatedDate = user.UpdatedDate
}).AsEnumerable().Select(m => new { ID = m.ID, Name = m.Name, UserName = m.UserName, Email = m.Email, UserType = m.UserType, CreatedDate = String.Format("{0:d/M/yyyy HH:mm:ss}", m.CreatedDate), UpdatedDate = String.Format("{0:d/M/yyyy HH:mm:ss}", m.UpdatedDate) }),
};
我怎么能用这个 lambda 表达式做到这一点?