Questions tagged [linq-query-syntax]

Language-Integrated Query is the name for a set of technologies based on the integration of query capabilities directly into the C# language.

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. With LINQ, a query is a first-class language construct, just like classes, methods, events.

Full Overview: https://learn.microsoft.com/en-us/dotnet/csharp/linq/index

86 questions
2
votes
2 answers

Entity Framework query with "not in"

I have a simple (well easy, not simple) query of "not in" on related tables. SELECT CompetencyID, CompetencyName FROM Competency WHERE (Deleted = 0) AND (CompanyID = 1) AND (CompetencyID NOT IN(SELECT CompetencyID FROM CompetencyGroups WHERE…
ransems
  • 641
  • 7
  • 19
2
votes
1 answer

Can I specify Queryable.GroupBy (instead of Enumerable.GroupBy) in query expression syntax

When I write a Group By in query expression syntax, the compiler automatically picks Enumerable.GroupBy as my intended tareget method and I get an IEnumerable back instead of an IQueryable. That means a subsequent g.Sum call (inside of my Select)…
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
2
votes
4 answers

Convert stored procedure to LINQ

I'm using MVC3 and still learning LINQ. I'm having some trouble trying to convert a query to LINQ to Entities. I want to return an Json method My stored procedure Create Procedure [dbo].[ResourceReports] ( @EmployeeID int ) as begin select…
1
vote
1 answer

Linq Query to get last entry of every year in the last x years

I have a table in an MSSQL table which contains usage data. For a report I need to load only the last entry of every year in the last 10 years. Example ID | Hits | GeneratedAt 1 | 12 | 20171231 2 | 35 | 20161231 3 | 5 …
Mr Quant
  • 104
  • 9
1
vote
2 answers

Check if any database table has any rows

I am trying to understand how to check if any table in my db has data using entity framework. I can check for one table but how can I check for all tables at once? DO we have any option with ef6? using (var db = new CreateDbContext()) { …
Kurkula
  • 6,386
  • 27
  • 127
  • 202
1
vote
1 answer

Entity Framework: generate dynamic where clause and select custom columns

I have 3 tables: Person, PersonFriend, PersonGroup. Using LINQ, i want to join the 3 tables, filter using a dynamically generated where clause, and select custom columns with flattened rows (flattened one-to-many relationship table…
Blee
  • 87
  • 2
  • 12
1
vote
1 answer

Using Menu Buttons to modify LINQ search terms

In VBS 2015, I have created a form that uses a LINQ query to import a CSV file of names, locations, ages, ect., sorted using a unique record. The data is input into a Data Grid and then may be filtered and sorted by the selection of buttons from the…
IIKCARUS
  • 13
  • 5
1
vote
2 answers

Filtering child collection with subquery

I have a query in sql, as shown in the code below: select * from Registration r inner join RegistrationService rs on rs.RegistrationID = r.RegistrationID inner join Service s on s.ServiceID = rs.ServiceID where cast(RegistrationDate as DATE)…
Willy
  • 1,689
  • 7
  • 36
  • 79
1
vote
2 answers

Linq query with first or default join

I have the following data model: public class Course { public int CourseId { get; set; } public int StateId { get; set; } } public class CompletedCourse { public int CompletedCourseId { get; set; } public int UserId { get; set; } …
mellis481
  • 4,332
  • 12
  • 71
  • 118
1
vote
3 answers

How can I use this extension method in a linq to entities query using query syntax?

I am creating a query to return some data from a database. I am passing in a list of ids that I want to filter on. If the filter list is null or empty I want to return all the things. I have an extension method that lets me do this query is an…
Loofer
  • 6,841
  • 9
  • 61
  • 102
1
vote
2 answers

Linq Conditional DefaultIfEmpty query filter

I have a query as below: bool variable = false//or true var query = from e in _repository.GetAll() from u in e.Users where (e.AuditQuestionGroupId != null ? e.AuditQuestionGroupId : 0) ==…
Rhys Stephens
  • 889
  • 3
  • 20
  • 36
1
vote
1 answer

When using Query Syntax in C# "Enumeration yielded no results". How to retrieve output

I have created this query to fetch some result from database. Here is my table structure. What exaclty is happening. DtMapGuestDepartment as Table 1 DtDepartment as Table 2 Are being used var dept_list= from map in…
Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286
1
vote
1 answer

How to create Query syntax for multiple DataTable for implementing IN operator of Sql Server

I have fetched 3-4 tables by executing my stored procedure. Now they resides on my dataset. I have to maintain this dataset for multiple forms and I am not doing any DML operation on this dataset. Now this dataset contains 4 tables out of which i…
Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286
1
vote
1 answer

Entity Framework Query for Complex Sql

Anyone know how to represent this as an Entity Framework query? Either method syntax or query syntax is fine. Declare @UserId int = 18 Select * From [Profiles] Where [Profiles].[ProfileId] IN( Select [SecurityProfileAssignments].[ProfileId] …
aBetterGamer
  • 5,119
  • 2
  • 18
  • 19
1
vote
1 answer

Conditional logic with linq query syntax

I have the below conditional which executes one of two queries that solely differ by the additional clause && acc.Fb_DataSourceKey == dskId Here's the conditional var statData = dskId != -1 ? from s in dao.fb_statdata …
sming
  • 801
  • 2
  • 12
  • 25