LINQ 表达式 select 基于可见性 asp.net
LINQ expression to select based on visibility asp.net
所以我有一个包含 post
个对象的列表,这些对象具有 visibility
枚举 属性。我正在尝试获取所有包含 visibility == visibility.public
和 visibility == visibility.private && AuthorId == currentUserId
.
的帖子
这似乎不起作用:from e in list select (e.Visibility == Visibility.Public && (e.Visibility == Visibility.Private && e.Author.Id == userId))
如有任何帮助,我们将不胜感激
您要求 post 同时具有可见性 public 和私有。你的两个条件应该使用 OR 而不是 AND。
你的条件应该是e.Visibility == Visibility.Public || (e.Visibility == Visibility.Private && e.Author.Id == userId)
注意 ||
试试这个
var filteredList = list.Where(x => x.Visibility == Visibility.Public || (x.Visibility == Visibility.Private && x.AuthorId == currentUserId)).ToList();
所以我有一个包含 post
个对象的列表,这些对象具有 visibility
枚举 属性。我正在尝试获取所有包含 visibility == visibility.public
和 visibility == visibility.private && AuthorId == currentUserId
.
这似乎不起作用:from e in list select (e.Visibility == Visibility.Public && (e.Visibility == Visibility.Private && e.Author.Id == userId))
如有任何帮助,我们将不胜感激
您要求 post 同时具有可见性 public 和私有。你的两个条件应该使用 OR 而不是 AND。
你的条件应该是e.Visibility == Visibility.Public || (e.Visibility == Visibility.Private && e.Author.Id == userId)
注意 ||
试试这个
var filteredList = list.Where(x => x.Visibility == Visibility.Public || (x.Visibility == Visibility.Private && x.AuthorId == currentUserId)).ToList();