[英]How to frame Linq Query for this condition
My Table fileds and values: 我的表格文件和值:
IdFavorite : 1,2,3,4,5 IdFavorite :1,2,3,4,5
FavoriteName : Fav1, Fav2, Fav3, Fav4, Fav5 FavoriteName :Fav1,Fav2,Fav3,Fav4,Fav5
UserId : 1, 3, 3, 4, 3 UserId : 1,3,3,4,3
PublicFavorite : 0, 1, 0, 1, 0 PublicFavorite : 0,1,0,1,0
As of now I used following Linq query to get the list of Favorite Names basd on the User ID 截至目前,我使用以下Linq查询获取基于用户ID的收藏夹名称列表
public IList<ReportFavorite> GetReportFavorites(int userId)
{
return _reportFavoriteRepository.GetMany(x => x.UserId == userId).ToList();
}
Now, the condition is as above plus , I need to get all the Favorite Names that has PublicFavorite is 1. I need the Linq query according to this condition. 现在,条件是上面加 ,我需要得到所有喜欢的地名有PublicFavorite为1。我需要根据这个条件LINQ查询。 Thanks. 谢谢。
For eg: If My User Id is 3, then I should get the Favorite Names as Fav2 , Fav3 , Fav5 and also Fav4 (since PublicFavorite is 1) 例如:如果我的用户ID为3,那么我应该将喜爱的名称作为Fav2 , Fav3 , Fav5以及Fav4 (因为PublicFavorite为1)
var res =
from item in _reportFavoriteRepository
where item.UserId == userId || item.PublicFavorite == publicFavorite
select item.FavoriteName;
I used the following code as per Jon's comment. 根据Jon的评论,我使用了以下代码。 It is working fine as expected. 按预期工作正常。
GetMany(x => x.UserId == userId || x.PublicFavorite == 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.