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. .NET (Core and Framework)
  4. How to use BETWEEN in ASP.NET CORE EF?

How to use BETWEEN in ASP.NET CORE EF?

Scheduled Pinned Locked Moved .NET (Core and Framework)
asp-netcsharpdatabasedotnethelp
3 Posts 3 Posters 8 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.
  • K Offline
    K Offline
    Khaled Mohamed Eissa
    wrote on last edited by
    #1

    I have this SQL Statement "SELECT vYear, EmpCode, VacType, DocNum, DocDate, DepCode, SecCode, vName, vStart, vEnd, vDays, LType, CUsrName, CDate, MUsrName, MDate, Result, Reson, EmpCode_Act, MngID FROM NetVac WHERE ('12/07/2022' BETWEEN vStart AND vEnd) AND (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) OR (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) AND (CONVERT(DATETIME, '2022-07-13 00:00:00', 102) BETWEEN vStart AND vEnd)" and it work fine, i would like to do the same with EF but not using ADO or >,< Can anybody help me

    P J 2 Replies Last reply
    0
    • K Khaled Mohamed Eissa

      I have this SQL Statement "SELECT vYear, EmpCode, VacType, DocNum, DocDate, DepCode, SecCode, vName, vStart, vEnd, vDays, LType, CUsrName, CDate, MUsrName, MDate, Result, Reson, EmpCode_Act, MngID FROM NetVac WHERE ('12/07/2022' BETWEEN vStart AND vEnd) AND (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) OR (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) AND (CONVERT(DATETIME, '2022-07-13 00:00:00', 102) BETWEEN vStart AND vEnd)" and it work fine, i would like to do the same with EF but not using ADO or >,< Can anybody help me

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      If you are using Entity Framework and you want to use BETWEEN, the standard way is to use => and<=.

      Advanced TypeScript Programming Projects

      1 Reply Last reply
      0
      • K Khaled Mohamed Eissa

        I have this SQL Statement "SELECT vYear, EmpCode, VacType, DocNum, DocDate, DepCode, SecCode, vName, vStart, vEnd, vDays, LType, CUsrName, CDate, MUsrName, MDate, Result, Reson, EmpCode_Act, MngID FROM NetVac WHERE ('12/07/2022' BETWEEN vStart AND vEnd) AND (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) OR (vYear = 2022) AND (EmpCode = 5229) AND (VacType <> 10) AND (VacType <> 15) AND (VacType <> 16) AND (VacType <> 17) AND (VacType <> 18) AND (VacType <> 19) AND (VacType <> 20) AND (VacType <> 21) AND (VacType <> 23) AND (VacType <> 24) AND (Result <> 1) AND (CONVERT(DATETIME, '2022-07-13 00:00:00', 102) BETWEEN vStart AND vEnd)" and it work fine, i would like to do the same with EF but not using ADO or >,< Can anybody help me

        J Offline
        J Offline
        jsc42
        wrote on last edited by
        #3

        I'd start by looking at what your SQL is trying to do and simplify it. From what I can see, your WHERE clause can be reduced to

        	vYear = 2022
        	AND EmpCode = 5229
        	AND NOT VacType IN (10, 15, 16, 17, 18, 19, 20, 21, 23, 24) 
        	AND Result <> 1
        	AND ('12/07/2022' BETWEEN vStart AND vEnd
        		OR CONVERT(DATETIME, '2022-07-13 00:00:00', 102) BETWEEN vStart AND vEnd
        		)
        

        I do not understand what the date ranges are for and why there are two different ways of representing dates unless your data has two sets of texts neither as real dates, in which case the comparisons are meaningless.

        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