Questions tagged [sql-to-linq-conversion]

Use this tag for questions related to the conversion of SQL statements into LINQ statements.

224 questions
2
votes
2 answers

How to translate to Linq Expression

I have the following sql command which i cant translate into linq select Distinct(fp.Parks_Id) from ParkFeaturePark fp Inner Join Parkfeatures feat on fp.ParkFeatures_Id = feat.Id Inner Join Parks p On fp.Parks_Id = p.Id where p.Id In (Select…
gerald
  • 35
  • 1
  • 5
2
votes
1 answer

How to write a Linq query equivalent to this SQL

I'm trying to figure out how to write a linq query that will return equivalent results to the sql query below. The problem I'm having has to do with the two select count queries included in the select list of the main query. I need to get counts of…
Chris
  • 21
  • 1
2
votes
2 answers

Multiple Join and Group By LINQ

I need to generate this data model (example): IList fcf = new List(); fcf.Add(new FeatureGroupFeaturesDto { FeatureGroup = new FeatureGroupDto { Id = 1, Name = "Interior" }, Features = new…
Patrick
  • 3,561
  • 11
  • 52
  • 112
2
votes
1 answer

convert sql queries to linq queries

I am very new to LINQ ,I have made alot of unsuccessful attempts to convert a SQL query to LINQ.. Please help me out with some solution.What is the exact LINQ for this .. Thanks in advance. // Just a part of the entire query select distinct…
1
vote
1 answer

LINQ: How do i select 3 different column values from 3 different tables?

I have three tables Corevalue, SubjectType and Question. I want to select CoreValue.Sname, SubjectType.Cname and Question.QuestionText, I know how it works with SQL but not LINQ any help would be appreciated. Somethng like this in SQL: SELECT …
Obsivus
  • 7,521
  • 12
  • 48
  • 94
1
vote
2 answers

Convert SQL select statement to Linq

How can I convert the following SQL select statement to Linq? SELECT u.Name FROM User u AS DDC INNER JOIN Country c ON c.UserId = u.UserId INNER JOIN ( SELECT AddressId, Address, PC, FROM AddressTbl a …
Stavros
  • 4,954
  • 13
  • 30
  • 44
1
vote
2 answers

Nested selects in LINQ expression, how to?

I don't know how to work with nested selects in LINQ. How could I convert this SQl expression to LINQ? Select i.ID, i.Impression, (Select COUNT(ImpressionsId) from DiaryImpressions where DiaryPostsId = '2' AND ImpressionsId = i.ID) as Num…
Rubia Gardini
  • 815
  • 4
  • 15
  • 30
1
vote
1 answer

SQL to LINQ Involving Multiple GroupJoin

I have a SQL Query and would like to convert into LINQ Method Syntax (Lambda) but it seems that I am stuck at the multiple group join and it confuses me. Below is the SQL that I wanted to change into LINQ select MerchantUserId, usex.Nickname,…
1
vote
2 answers

Entity Framework Query with multiple join conditions

Edited I have tables Customers, Sites, Buildings and Addresses. Every customer has zero or more (one?) sites, every site is the site of exactly one customer, namely the site that the foreign key Site.CustomerId refers to. Similarly, every site has…
VIkas
  • 15
  • 6
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…
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,085
  • 13
  • 32
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…
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…
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
  • 4
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 2
3
14 15