Linq to SQL not like operator
The problem is the "%" - you're looking for things which literally don't contain "%TEST%" which would probably be everything. I think you mean:
var p = (from c in tablename
where !c.Value.ToUpper().Contains("TEST")
select c.Value).Distinct().ToList()
Not like in LINQ to SQL
Have you tried !s.ID.StartsWith("0000")
? (i.e. using the negation operator !
)
Use SQL LIKE operator in C# LINQ
There are lots of possibilities for Like in Linq:
For LIKE '%abc%';
list.Where(x => x.myTextColumn.Contains('abc'));
For LIKE 'abc%';
list.Where(x => x.myTextColumn.StartWith('abc'));
For LIKE '%abc';
list.Where(x => x.myTextColumn.EndsWith('abc'));
Updates : If you need to add Date comparison as well means you can do like the following:
DateTime date2Compare = new DateTime(2017, 1, 20);
list.Where(x => myDateColumn >= date2Compare && x.myTextColumn.Contains('abc'));
What is the SQL LIKE operator equivalent in LINQ having multiple % operators in the input text?
Posting the comments given by @Fabio and @CodeNotFound as answer for reference.
In EntityFramework version 6.2.0:
var users = (from usr in Context.Users
where DbFunctions.Like(usr.Username, "%test%email%")
select usr).ToList();
How would you do a not in query with LINQ?
I don't know if this will help you but..
NorthwindDataContext dc = new NorthwindDataContext();
dc.Log = Console.Out;
var query =
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID)
.Contains(c.CustomerID)
select c;
foreach (var c in query) Console.WriteLine( c );
from The NOT IN clause in LINQ to SQL by Marco Russo
How to use LIKE Operator in LINQ to Entity Framework
Do like this.
var result
= dbContext.Categories.Where(i => i.CategoryName.StartsWith("a")).ToList();
How to write not equal operator in linq to sql?
You need to revise the join to be on the related columns between the 2 tables, then you add your condition in the where clause, like the following:
using (RapidWorkflowDataContext context = new RapidWorkflowDataContext())
{
var query = from w in context.WorkflowInstances
join c in context.Workflows on w.WorkflowID equals c.ID
where EmpWorkflowIDs.Contains((int)w.ID)
&& w.CurrentStateID != c.LastStateID
select w;
return query.ToList();
}
How to do SQL Like % in Linq?
.Where(oh => oh.Hierarchy.Contains("/12/"))
You can also use .StartsWith()
or .EndsWith()
.
Related Topics
How to Test My Ad-Hoc SQL with Parameters in Postgres Query Window
Inserting Multiple Rows in Sybase Ase
Running Powershell Scripts Through SQL
Ssms: How to Import (Copy/Paste) Data from Excel
Ms Access Query with Case Statement
How to Escape Double Quotes Inside a SQL Fulltext 'Contains' Function
Refer to a Column Name Alias in the Where Clause
Insert Blank Row Between Groups of Rows and Sorted by Id in SQL
How to Create Sequence Using Starting Value from Query
Orderby in SQL Server to Put Positive Values Before Negative Values
How to Format Datetime as M/D/Yyyy in SQL Server
Version Number Sorting in SQL Server
SQL Server:Find Duplicates in a Table Based on Values in a Single Column
Using Regular Expression Within a Stored Procedure