• 主页
  • 隔离LINQ C#中的where子句

隔离LINQ C#中的where子句

我有以下代码

RoseFlowersData = (from c in dbContext.ClientFirst
                     where c.RoseFlower.Id == Id
                     select new FlowerDTO
                     {
                         flowerId = c.Id,
                         flowerCatergory = c.flowerCatergory
                     }),
AsterFlowerData = (from c in dbContext.ClientFirst
                       where c.AsterFlower.Id == Id
                       select new FlowerDTO
                       {
                           flowerId = c.Id,
                           flowerCatergory = c.flowerCatergory
                       }),

两者唯一的区别是where子句(where c.RoseFlower.Id == Id; where c.AsterFlower.Id == Id)

我想使用以下函数来获取基于不同花朵类型(如RoseFlower、AsterFlower等)的数据。

private IQueryable<FlowerDTO> GetFlowerData(int flowerId, <What should I pass here?>)
{
    var data = (from c in dbContext.ClientFirst
                where c.RoseFlower.Id == flowerId
                select new FlowerDTO
                {
                    flowerId = c.Id,
                    flowerCatergory = c.flowerCatergory
                });
    return data;
}       

我对如何将此函数用于花朵类型和其他类型感到困惑。我试图寻找解决方案来隔离where子句,但经过几个小时的搜索,我一直无法找到解决方案。也许我没有在寻找正确的东西。

感谢您的时间和帮助

转载请注明出处:http://www.jxbyjx.net/article/20230502/2447430.html