Use this tag for questions related to the conversion of SQL statements into LINQ statements.
Questions tagged [sql-to-linq-conversion]
243 questions
1
vote
1 answer
Filtering on the Collection Navigation property
I would like to filter my 'TranslationSet' entities, based on their 'Translations' Collection Navigation Property.
E.g.
If a 'Translation' has a 'LanguageId' of 5 (Italian), then the 'TranslationSet' that contains this 'Translation' should be…

Matteo
- 13
- 3
1
vote
2 answers
Linq query of left outer join not properly working
I converted sql query to linq query without any error.
Now, my question is that I get the data properly in sql query, while in linq query showing the whole data without filtering product null.
Here is my code:
SQL Query
SELECT Name
FROM…

s.k.Soni
- 1,139
- 1
- 19
- 37
1
vote
1 answer
EF Core: The LINQ expression could not be translated for a nested List with Generic StartsWith() Expression
I'm trying to build kind of a generic "StartsWith" Expression in a nested List that called 'OtherListEntities'. The managed entity looks like this:
public class MyEntity
{
[System.ComponentModel.DataAnnotations.Key] // key just for the…

Hamid Hajiparvaneh
- 19
- 3
1
vote
1 answer
EF LINQ Count by Grouped field
I have the following data schema:
With the following LINQ query:
var profiles = (
from p in context.BusinessProfiles
join u in context.Users on p.UserId equals u.Id
join addr in context.BusinessAddress on p.ProfileId equals…

Christos Lytras
- 36,310
- 4
- 80
- 113
1
vote
1 answer
LINQ syntax for SQL INNER JOINS
I'm a complete novice in linq.
I have a T-SQL statement that I don't know write in Linq.
The database tables structure looks like this: DB structure
The SQL code looks like this:
SELECT
e.PersonId, e.PhoneNoId, e.PhoneId, s.StateId,…

Rado
- 25
- 5
1
vote
1 answer
How to select top result for a given ID then join that into another table EF Core LINQ
For the life of me I am unable to google my way out of this one.
I have 2 tables within a database
1. Computers
2. UserLogins
Essentially, I'm trying to get the latest login entry from the "UserLogins" table, and join it with the corresponding…

Codestripper
- 43
- 5
1
vote
1 answer
LINQPad 6 how convert sql to linq
I have the premium version of LINQPad 6
do you know the steps to convert sql code to linq ?

David Alejandro García García
- 312
- 1
- 3
- 18
1
vote
0 answers
Convert SQL Query to LINQ query/Lambda expression
I am trying to fetch the results from the DB using the Entity Framework using the below SQL query:
SELECT
Header_Id,
Header_Number, Details_Id,
Details_Header_Date,
(SELECT TOP 1 c.[Comment_Description] FROM [Comment] c
…

user1234
- 11
- 2
1
vote
3 answers
Change SQL Query to LINQ, asp.net MVC
How to change this SQL query to LINQ? I've tried it several times, but it didn't work
SELECT Payment.ID, Payment.TotalGroupID, PaymentTrans.PaymentID, PaymentTrans.TotalGroupID as TotalGroupID1, PaymentTrans.TransferStatus
FROM PaymentTrans INNER…

chaeusang chen
- 99
- 1
- 12
1
vote
1 answer
DefaultIfEmpty() does not handle empty collections
I've been trying to left join the table and they are in a one-to-many relationship.
I have written a SQL query and trying to convert it into LINQ for my ASP.NET Core application.
My sql query is as follows:
SELECT ap.SystemId,
…

Brown
- 83
- 9
1
vote
2 answers
SQL query to linq syntax
How can i convert this join stmnt to linq syntax
SELECT pv.Product_ID, pv.Product, v.Add_ID, v.Product_ID
FROM Product AS pv
JOIN Product_Add AS v
ON ((pv.Product_ID = v.Add_ID) OR (pv.Product_ID = v.Product_ID))
where(( pv.Product_ID =…

lilly
- 11
- 1
1
vote
0 answers
Count(Distinct x) in LINQ
I am trying to convert an SQL query to LINQ but i need to make use of HAVING Count(Distinct) which I am unable to do in LINQ and I cant seem to find an alternative to get the same results
SELECT
B.BranchCode ,
B.BranchName ,
…

ThatMightyBean
- 51
- 3
1
vote
1 answer
trying to convert sql to linq sql
I'm trying to convert this SQL code to linq sql. But I don't understand even with the doc... someone can help me please ?
select prcleunique, LibelleProjet, from projet a
where eqcleunique in (select EqCleunique from Compo where uscleunique = '{0}')…

Phantom
- 19
- 2
1
vote
1 answer
LINQ Method Syntax to INCLUDE 4 Levels Deep
I have been searching without success (or not knowing how to search for this properly) so I come to you.
Check out these test classes:
public class A {
int Id;
ICollection Bs;
}
public class B {
int Id;
int AId;
ICollection…

RoLYroLLs
- 3,113
- 4
- 38
- 57
1
vote
2 answers
SQL to LINQ - Left Join Before Inner Join
So I have a SQL query that I would like to convert to LINQ.
Here is said query:
SELECT *
FROM DatabaseA.SchemaA.TableA ta
LEFT OUTER JOIN DatabaseA.SchemaA.TableB tb
ON tb.ShipId = ta.ShipId
INNER JOIN DatabaseA.SchemaA.TableC tc
ON…

wibby35
- 97
- 1
- 1
- 9