unfortunately, linq does not have a between operator or equivalent. the best (and possibly) only way to achieve this is in sql.
if you are looking to write complex or optimized queries, it is better to use sql rather than linq. the main advantages for this are:
- code can be fully tested in management studio, without having to translate and debug in a second language
- for legacy purposes, it is generally better to use sql for database access code, as this is more widely known amongst database experts. linq is the curse of dbas who have to manage/support code written by others.
i agree with gerge mauer's suggestion to use a stored procedure or ado.
this might still leave you with the problem of parameter sniffing, in which case you may have to use query hints such as optimize for / recompile, or local variables to get around this, as demonstrated in this article:
- Force LINQ to SQL or ENTITIES to emit BETWEEN operator
- LINQ to Entities using the SQL LIKE operator
- SQL 'IN' operator in LINQ to Entities
- BETWEEN operator for string in LINQ to SQL query
- Linq to Entities - SQL "IN" clause
- What is the linq equivalent to the SQL IN operator
- How are people unit testing code that uses Linq to SQL
- LINQ Between Operator
- Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator
- LINQ to Entities generating incorrect SQL
- LINQ To SQL exception: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains operator
- LINQ to SQL value BETWEEN two double values
- How to force LINQ to SQL to evaluate the whole query in the database?
- How do you do a SQL style 'IN' statement in LINQ to Entities (Entity Framework) if Contains isn't supported?
- Equivalent of SQL Between Statement Using Linq or a Lambda expression
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Use SQL LIKE operator in C# LINQ
- LINQ to Entities equivalent of sql "TOP(n) WITH TIES"
- Like operator or using wildcards in LINQ to Entities
- Linq to SQL "not like" operator
- LINQ to SQL - best way to switch between test & dev db
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- SQL Rank in LINQ to Entities
- Expression to get LINQ with Contains to EF for SQL IN() where on entities child's property equals value
- linq to entities generated sql
- Linq to Sql - Loading Child Entities Without Using DataLoadOptions?
- Linq 2 SQL or Linq Entities
- LINQ Source Code Available
- Differences between LINQ to Objects and LINQ to SQL queries
- How can I share Linq to Entities datacontracts between WCF and Silverlight
More Query from same tag
- linq compare column data between two dates
- Linq add missing distinct values
- XElements by Attribute Name
- Building a dynamic where clause for dynamic keywords or using IQueryable C# Linq
- LINQ Order List By SubObject with possible Null Reference
- CS0176 Compiler error. What does it mean an how do I solve it
- Strange behavior with IEnumerable/IQueryable extension (no lazy loading?)
- how to use linq to sql with if using
- Dictionary lookup with LinQ to find a subset where the Value is a List element
- Is there a other way to Group or Merge a separated Collection of List<T> and store the List<T> to the index of new List<T>?
- LINQ Statement Optimization - Seeking advice for better design
- How can I move next/previous in List using LINQ?
- How can you take only the last result with Linq
- Generate sequence with step value
- Stored procedure not making transaction
- Check union of delimited strings for duplicates
- Get specific column from a dapper result set
- LINQ Expression Tree: Call Any method against a DbSet
- How to split string where string starts with "<input " using linq in c#
- Select unknown item from multi-dimensional array using LINQ
- Return parent entities based on (and including) child entities
- Why do Users and Roles for ASP.NET identity not appear in Db Context
- Searching a tree using LINQ
- c# to vb.net linq select
- Support for entity framework Linq statement (with a subquery)?
- Using two tables from the database with the Entity Framework
- Display specific rows and update in GridView using Linq database c#
- Is the Specification Pattern obsolete when you can use Dynamic LINQ?
- Technique for dynamically adding a join to a linq query?
- Is there a more succinct Linq expression for inserting a constant between every item in a list?