LINQ is it possible to add where clauses dynamically

前端 未结 5 1343
青春惊慌失措
青春惊慌失措 2021-01-05 02:36

I want to search my db with different keys. According to the input, there may be 1 key to 10 keys. Is there a way to add OR/AND clauses to my Linq query dynamically?

5条回答
  •  天涯浪人
    2021-01-05 03:02

    You can use the extension methods of LINQ

    ctx.Feed.Where(f => {  
    //Your logic here
    if(something != null){
          return f.Property == something
      } 
    }).Select( new { FeedId = feed.DuyuruId,
                        FeedTitle = feed.FeedTitle,
                        FeedContent = feed.FeedContents,
                        FeedAuthor = user.UserName + " " +User.UserSurname })
    

提交回复
热议问题