I've got the following SQL:
select * from transaction_log where stoptime like '%2008%'
How do I write this in LINQ to SQL syntax?
In LINQ to SQL, we don't have a LIKE operator, but by using contains(), startswith(), and endswith() methods, we can implement LIKE operator functionality in LINQ to SQL.
LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the LINQ to SQL API to request query execution. The LINQ to SQL provider then transforms the query into SQL text and delegates execution to the ADO provider.
This query returns two groups based on the first letter of the word. List<int> numbers = new() { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; // The query variables can also be implicitly typed by using var // Query #1. IEnumerable<int> filteringQuery = from num in numbers where num < 3 || num > 7 select num; // Query #2.
"As long as LINQ to SQL lives under Entity Framework, it's dead.
If you want to use the literal method, it's like this:
var query = from l in transaction_log
where SqlMethods.Like(l.stoptime, "%2008%")
select l;
Another option is:
var query = from l in transaction_log
where l.stoptime.Contains("2008")
select l;
If it's a DateTime:
var query = from l in transaction_log
where l.stoptime.Year = 2008
select l;
That method is in the System.Data.Linq.SqlClient namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With