Use this tag for questions related to the conversion of SQL statements into LINQ statements.
Questions tagged [sql-to-linq-conversion]
243 questions
                    
                    11
                    
            votes
                
                3 answers
            
        Linq union usage?
Sql:
SELECT date,total_usage_T1 as TotalUsageValue,'T1' as UsageType FROM TblSayacOkumalari
UNION ALL
SELECT date,total_usage_T2 as TotalUsageValue,'T2' as UsageType FROM TblSayacOkumalari
And I try to do to convert it to…
         
    
    
        AliRıza Adıyahşi
        
- 15,658
- 24
- 115
- 197
                    7
                    
            votes
                
                1 answer
            
        SQL to LINQ with multiple join, count and left join
I wrote this SQL request with multiple JOIN (including a LEFT JOIN).
It gives me the expected result.  
SELECT DISTINCT c.Id, 
       c.Title, 
       COUNT(v.Id) AS 'Nb_V2',
       COUNT(DISTINCT v.IdUser) AS 'Nb_V1',
       r.cnt AS 'Nb_R'
FROM…
         
    
    
        user2687153
        
- 427
- 5
- 24
                    7
                    
            votes
                
                1 answer
            
        How to do left joins in LINQ on multiple fields in single join
I am trying to do this simple sql query to LINQ. But its give me error.
Here is the SQL query that need to conver to LINQ
 DECLARE @groupID int
 SET @groupID = 2
 SELECT * 
    FROM dbo.Person p
    LEFT JOIN dbo.PersonGroup pg ON ( p.PersonID =…
         
    
    
        Monirul Islam
        
- 985
- 1
- 8
- 23
                    6
                    
            votes
                
                2 answers
            
        Using LINQ find nearby places from database
We want to receive list of nearby places from database using LINQ in ASP.NET 2012 and would like some feedback on our strategy.
My table and fake data:
     PlaceId    Name       Latitude   Longitude 
       1          A          18.1        20.1
 …
         
    
    
        Swapneel Kondgule
        
- 842
- 8
- 27
                    5
                    
            votes
                
                2 answers
            
        Merge 2 lists based on one property and concatenate other properties
IList ob1 = {new MyObject {Id = "1", Items = {BananaObject1, BananaObject2}}}  
IList ob2 = { new MyObject {Id = "1", Items = {BananaObject2, BananaObject3}},  
new MyObject {Id = "2", Items = {BananaObject3, BananaObject3}}}
I…  
         
    
    
        E. K.
        
- 63
- 1
- 6
                    5
                    
            votes
                
                1 answer
            
        LINQ with Group By and Having Clause with Min(string)
There are examples with group by - having count or select minimum date with linq on the web but I couldn't find a particular solution for my question. And also I don't have an advanced linq understanding to combine these solutions that I found so…
         
    
    
        Baz Guvenkaya
        
- 1,482
- 3
- 17
- 26
                    5
                    
            votes
                
                4 answers
            
        SQL LIKE in Linq
Before adding this question, I did search on stackoverflow for similar ones but I couldnt find. Most of the questions over internet were using LIKE with a string (for eg LIKE '%ABC%') but I need to compare with an existing column of a different…
         
    
    
        Sai
        
- 629
- 1
- 8
- 26
                    5
                    
            votes
                
                2 answers
            
        Converting an SQL query in to LINQ C#
I've an SQL Query:
SELECT 
      node.GroupName
    , depth = COUNT(parent.GroupName) - 1
FROM CompanyGroup node
JOIN CompanyGroup parent ON node.LeftID BETWEEN parent.LeftID AND parent.RightID
GROUP BY node.GroupName, node.LeftID
ORDER BY…
         
    
    
        Jimmy
        
- 2,191
- 6
- 25
- 45
                    5
                    
            votes
                
                3 answers
            
        convert sql to linq
I am trying to implement a Filter by Date on my hotel reservation project. 
Could somebody help me please to convert this sql  code to linq .
SELECT r.*
FROM Room r LEFT JOIN Reservation v ON r.RoomID = v.RoomID
AND NOT (@StartDate >= Date_Check_Out…
         
    
    
        jonny
        
- 797
- 4
- 24
- 41
                    4
                    
            votes
                
                1 answer
            
        Transforming SQL into Linq To Objects expressions at runtime
Does anyone know of any libraries that one can use to parse a SQL query and build up a linq expression which can then be compiled and used against linq to objects?
This approach only needs to work for simple queries, for complex ones I can write a…
         
    
    
        mcintyre321
        
- 12,996
- 8
- 66
- 103
                    4
                    
            votes
                
                1 answer
            
        How to convert Sum over partition from T-SQL
I have the following T-SQL Table, data, and query.
create table sampledata 
(
    name nvarchar(50),
    sampletime datetime,
    samplevalue decimal
);
insert into sampledata (name, sampletime, samplevalue) values
('ABC1235', cast('2016/01/01…
         
    
    
        Grizzly Bear
        
- 97
- 7
                    4
                    
            votes
                
                3 answers
            
        Convert SQL to Linq where there is in clause
I would like to know how to convert SQL query listed below into LINQ query in VB.
SELECT FacilityID 
FROM tblFacilityProjects 
WHERE FreedomEnabled = True and ProjectID in (840,841,842)
         
    
    
        slamsal
        
- 610
- 9
- 13
                    3
                    
            votes
                
                2 answers
            
        SQL to LINQ in C# (query with several tables and alias)
Is there somebody that could translate this query to Linq in C# . I was searching and I didn't find any query similiar to.
Thanks a lot guys!
SQL Sentence:
SELECT a.Amenaza, c.Nombre, c.Descripcion
 FROM AmenazasEstablecer a, ControlesEstablecer c,…
         
    
    
        Antonio
        
- 31
- 1
- 2
                    3
                    
            votes
                
                1 answer
            
        Cannot access Table in converted query (plain SQL to LINQ)
I'm trying to convert this working SQL query into a LINQ query (EF)
But in the LINQ query I can't get into the category data table.
This is my working  SQL Query:
SELECT cosmetics.brand, cosmetics.product, cosmetics.size, cosmetics.price,…
         
    
    
        ari
        
- 31
- 1
                    3
                    
            votes
                
                1 answer
            
        SQL Where in to Linq with DataTable
I'm trying to achieve this in c#
Select a.Name,a.Param
from Customization a
where a.name in (select Name from Standard)
I have try something like this but it still doesn't work.
 merge = dt1.AsEnumerable()
            .Where(r =>…
         
    
    
        K.S
        
- 33
- 3