Linq中用于实体的动态WHERE子句(OR)
如果使用OR逻辑,如何实现相同的查询?
public User GetUser(IdentifierType type, string identifier){ using (var context = contextFactory.Invoke()) { var query = from u in context.Users select u; if (type.HasFlag(IdentifierType.Username)) query = query.Where(u => u.Username == identifier); if (type.HasFlag(IdentifierType.Windows)) query = query.Where(u => u.WindowsUsername == identifier); return query.FirstOrDefault(); }}
慕哥9229398
慕运维8079593