Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Using two or more Where in a query in EF

Using two or more Where in a query in EF

Scheduled Pinned Locked Moved LINQ
questiondatabase
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Majid Shahabfar
    wrote on last edited by
    #1

    How can I use OR between two or more Where in a query in EF like this?

    var docs = Documents.Where(c=>c.Title.Contains("string").Where(c=>c.Subject.Contains("string"));

    I R 2 Replies Last reply
    0
    • M Majid Shahabfar

      How can I use OR between two or more Where in a query in EF like this?

      var docs = Documents.Where(c=>c.Title.Contains("string").Where(c=>c.Subject.Contains("string"));

      I Offline
      I Offline
      Ian McCaul
      wrote on last edited by
      #2

      Try this

      var docs = Documents.Where(c=>c.Title.Contains("string") || c.Subject.Contains("string"));

      R 1 Reply Last reply
      0
      • M Majid Shahabfar

        How can I use OR between two or more Where in a query in EF like this?

        var docs = Documents.Where(c=>c.Title.Contains("string").Where(c=>c.Subject.Contains("string"));

        R Offline
        R Offline
        r3m1x
        wrote on last edited by
        #3

        In Linq2Sql I would have done this: var docs = Documents.Where(c => c.Title.Contains("string") && c.Subject.Contains("string")); Most likely it will work for ef too. Hope it helps!

        1 Reply Last reply
        0
        • I Ian McCaul

          Try this

          var docs = Documents.Where(c=>c.Title.Contains("string") || c.Subject.Contains("string"));

          R Offline
          R Offline
          r3m1x
          wrote on last edited by
          #4

          Wouldn't the statement be OR? Does he want and? Unless that is what he wants I apologize :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups