Most voted "linq" questions
Language Integrated Query (LINQ) is a component of Microsoft. NET Framework that adds native data query (query) functionality in . NET languages.
Learn more…578 questions
Sort by count of
-
128
votes7
answers5450
viewsHow to write easy-to-maintain, readable code?
How to know if the code is easy to read and maintain? I usually abstract a large part of my codes, I have a habit of using a lot lambda functions in C#. As this function for CPF validation. public…
-
63
votes3
answers24262
viewsWhat is the difference between Ienumerable, Iqueryable and List?
What’s the difference between Ienumerable, Iqueryable and List no . NET? When it’s best to use one or the other? Why does Resharper suggest that I modify the return of that function, for example,…
-
24
votes2
answers4960
viewsWhat is the difference between "lambda" and LINQ? How to differentiate them in a sentence?
I often see terms like LINQ query and expressions lambda. Then the question arose, What I’m doing is a LINQ query, an expression lambda or both? Ex1: var query = Produtos.Where(p =>…
-
23
votes1
answer1280
viewsDifferences between declarative and imperative form of LINQ
What one way can do that the other can’t? There is a difference in performance? There’s one advantage over the other? Example: using System; using System.Collections.Generic; using System.Linq;…
-
22
votes3
answers11209
viewsDifference between Any, Contains and Exists
What’s the difference between Any, Contains and Exists? What is the appropriate context for each of them? (Examples of use) What are the advantages and disadvantages?…
-
19
votes3
answers1592
viewsWhat is System.Linq for?
I asked that question here at SOPT What is the equivalent of PHP’s C array_map#? And I was curious to know what this is about System.Linq. Because when I tried to use the answer code above without…
-
18
votes2
answers484
viewsIs there an opposite for `contains`?
I have a list: List<int> lista1 = new List<int>(); lista1.Add(1); lista1.Add(2); lista1.Add(3); List<int> lista2 = new List<int>(); lista2.Add(1); lista2.Add(2); To get the…
c# .net entity-framework linq lambda-expressionsasked 9 years, 4 months ago Jedaias Rodrigues 6,718 -
16
votes2
answers1245
viewsWhy is Addrange so much faster than Add?
I’m working on a data integration between two databases, and I’m using Entity Framework for that reason. I then generated the following code, which iterates each record in the Base Situations table…
-
15
votes2
answers1617
viewsWhat is LINQ technology?
Today reading some contest questions, appeared one in which it was LINQ technology. Without delving too much into the research I noticed a number of quotes as: LINQ to SQL LINQ to XML (C#) LINQ to…
-
14
votes3
answers261
viewsWhat is the advantage of using the Set<> method?
What is the advantage or difference in using the method Set<> and I can do the same thing without him as in Alternative 2? Alternative 1 var aluno = contexto.Alunos.First(x => x.Id ==…
-
13
votes2
answers141
viewsHow to Lambda in Extension Methods with Multiple Lists?
There are the following Objects: public class Objeto1 { public List<Objeto2> PropObj1 {get; set;} } public class Objeto2 { public List<Objeto3> PropObj2 {get; set;} } public class…
c# .net entity-framework linq lambda-expressionsasked 9 years, 4 months ago Jedaias Rodrigues 6,718 -
12
votes1
answer3277
viewsHow does the Linq Aggregate() extension method work?
I just saw some examples that used the method Aggregate() of namespace System.Linq, but I couldn’t find any good explanation for how to use it. What does this method and how it should be used?…
-
12
votes2
answers437
viewsPerformance difference of Any() and Count()
When I need to check whether a Collection has or has not elements which of the two methods will be faster, .Count() =! 0 or .Any()? I’ve heard that the .Count() may be faster in some cases. But by…
-
12
votes2
answers815
viewsHow does the logic of Where in the Entity Framework work?
I’m studying C# and I just made my first query in the Database: using System; using System.Data.Entity.Core; using System.ComponentModel.DataAnnotations; using…
-
11
votes2
answers1153
viewsConsulta Lambda
I have the following consultation at T-SQL: SELECT TOP (60) COUNT(*) AS QTD, SUM(Duration) AS Total, AVG(Duration) AS Media, MIN(Duration) AS Menor, LEFT (TextData, 80) AS TextData FROM Traces WITH…
-
11
votes2
answers197
viewsNomenclature or language in lambda
We have that expression: var teste = meucotexto.minhatable.Where(x => x.meu_campo.....) How I read that part x => x.meu_campo Leio x is for x.meu_campo or x of x.meu_campo or something else?…
-
11
votes3
answers175
viewsWhat is the most correct way to make a query with LINQ?
I am trying to make a LINQ query in my BD SQL Server, but the result of it always comes 'null'. I need the first user ID I query. This is the way I try to consult: public decimal…
-
11
votes2
answers14331
viewsHow does Groupby work on LINQ?
I’m having trouble understanding the operator Groupby on LINQ.
-
11
votes3
answers2766
viewsCount or Count()
Having a list, what better way to know the number of items on this list and what the difference? if (minhaLista.Count > 0) ; or if (minhaLista.Count() > 0) ;…
-
11
votes2
answers1625
viewsLambda Groupby by year and month
I have a list of events, and I’d like to group them by year and month, for example [Year 2017] Month January { Event 1, Event 2, Event 2 } Month February { Event 3 } [Year 2018] Month January {…
-
10
votes5
answers2566
viewsIs it recommended to use Linq instead of SQL?
To avoid string abuse and avoid code injection problems can be a good practice using the Linq. I can also imagine, for example, that it’s slower. Who ever used the Linq to communicate with the…
-
10
votes1
answer9035
viewsScroll bar on a table with bootstrap
I have a table, where I upload database information into it. It has two columns (CNPJ and Social Reason). The table I mounted with bootstrap. I would like her to have a maximum height and create a…
-
10
votes2
answers16045
viewsForeach or lambda in lists
Which one do I get the best performance to get the value of a given in a list? I do foreach or lambda(when possible, of course)? I can have this: foreach(var i in lista) { var teste = i.NmCampo; }…
-
10
votes2
answers375
views -
10
votes1
answer5341
viewsOrder By with List<>
It is possible to make a OrderBy in a List<> setting the value for comparison? Example: mRel.OrderBy(s => s.Status == EnumModel.StatusGeral.Novo).ToList() My Code:…
-
10
votes2
answers487
viewsHow to sort by two properties in Linq
I have the following syntax and it’s not working return View(trabalhos.Where(a => a.Usuario == User.Identity.Name && a.Data.Month == DateTime.Today.Month && a.Data.Year ==…
-
9
votes1
answer5672
viewsLeft Join with lambda Groupjoin and with condition
How can I make one left join with some conditions using lambda LINQ expressions? In SQL Server have this query: select usr.Id, usr.FirstName, usr.LastName, ex.Id from User usr left join Exam ex on…
-
9
votes2
answers1167
viewsForeach of C# vs Foreach() of EF6
Follows code: ForEach() of EF6: var result = ctx.Table.Where(x => x.User == "João").ToList(); result.ForEach(x => x.Read = true); ctx.SaveChanges(); foreach of the C#: var result =…
-
9
votes3
answers1480
viewsHow to make a query through LINQ ignoring accents?
I wonder if it is possible to make a query with LINQ to compare two strings and ignore their accents. That without my Collation in the database is set as AI (Accent Insensitive) and I don’t need to…
-
8
votes2
answers1261
viewsHow to get all records from a mixed table generated by class inheritance when using Entityframework 6?
I have a class structure in the following form: public class Pessoa { public int Id {get; set;} public string Nome {get; set;} } public class Membro : Pessoa { public int CargoId {get; set;} public…
-
8
votes2
answers362
viewsHow do I convert LINQ to SQL for Mysql?
I am trying to remove the use of SQL statements from within the system (to make it flexible as to which database will be used), use instructions Insert, Update and Delete via stored Procedure…
-
8
votes3
answers1242
viewsLINQ with Where condition using variable
I have the following table: USUARIO Nome | Idade João | 21 Maria | 18 I want to do in only one consultation return all users, or return only users of specific age based on a C variable#. Also by…
-
8
votes1
answer89
viewsHow do I extract values from an Expression?
Hello. It is possible to extract from an Expression which filters, arrays, etc were used in a query? Example: public class Program { class Produto { public int Id; public string Nome; public…
-
8
votes2
answers1332
viewsConvert string to Datetime in LINQ
I have a model where all fields are string. I want to convert to DateTime and Double For that I created a new model public class CPUStats { public DateTime Data { get; set; } public Double? Disco {…
-
7
votes1
answer1780
viewsHow do I know if at least one element of a list is contained in another list?
I have two lists: var lista01 = new List<int> { 1, 2, 3, 4, 5 }; var lista02 = new List<int> { 7, 7, 7, 7, 7 }; I need to check if at least one element of list 1 exists on list 2, then…
-
7
votes4
answers298
viewsHow to implement an Objectset wrapper that works with Linqtoentities?
I need to create a wrapper for ObjectSet to create a centralized access control. The goal is to implement CA without making changes to existing queries in the system, which in this case are spread…
-
7
votes4
answers2652
viewsDo an update with lambda
I have a query in lambda that returns me a list of data. I wonder how I do to update this table of BD using lambda? Let’s say, I have a table called T_PDV and in it a flag field, where LIDO = 1 and…
-
7
votes2
answers5079
viewsHow to count records (SELECT COUNT) in Linq
How to count records that a query would return in Linq (Entity Framework) in C#? The equivalent in SQL is to do a SELECT COUNT(*). Note that I want to receive the count of records straight away,…
-
7
votes1
answer183
viewsLambda with different contexts
Is there any way to join two or more tables using Lambda and two different contexts?
-
7
votes1
answer481
viewsPopulate aggregate class from datatable using a Dataset with LINQ C#
I’m having trouble filling an aggregate class in C#. Is it possible using LINQ? Does anyone have any example of how to solve this problem using the return of a DataTable or DataSet? public class…
-
7
votes3
answers660
viewsLINQ corresponding to SQL with clause LIKE 'XXX%'
I am using the following LINQ to return a query: .Where(c => c.Nome.Contains(nome)).OrderBy(c => c.Nome) But if the name is Maria, he brings: José Maria Maria José How to bring organized as if…
-
7
votes2
answers1398
viewsReturning a list using select new with LINQ
I can do it: var filial = (from f in base.EntityContext.vw_filial select f).ToList<vw_filial>(); But I want to do something like this: var filial = (from f in base.EntityContext.vw_filial…
-
7
votes2
answers3355
viewsSearch item in a list using LINQ
I have a list and want to search it (as if it were a database). It is possible? Ex: list all names from the list that start with 'JOAO%'
-
7
votes1
answer272
viewsFill in a collection type property
Good personal evening how to fill a collection property using this type of structure in a class: public class Order { public string orderNumber {get; set; } public DateTime orderDate {get; set; }…
-
7
votes2
answers1801
viewslist.foreach vs foreach
I have a list of several string, there’s a difference between going through the list values: In this way: ListaString.ForEach(delegate(string str) { Console.WriteLine(str); }); Or this:…
-
7
votes3
answers414
viewsHow to change the structure of a LINQ query at runtime?
I have the following example of a program that implements the EF (Entity Framework). The structure of the database and the application is defined as follows: Table Pessoa: Primary key field:…
-
7
votes1
answer1804
viewsThe Entity or Complex type '*' cannot be constructed in a LINQ to Entities query
I can’t do this? public List<Filial> GetAll() { //Mostra todos os registros incluindo os desativados para os Administradores var ret = _db.Filiais.AsNoTracking() .Where(e => e.Visible)…
-
7
votes2
answers195
viewsLINQ query with sum
I have the following appointment at LINQ var dados = _db.Contratos .Where(a => a.Adesoes.Any(b => b.Pago)) .Select(a => new { Contrato = a.Numero, ValorTASenior = a.Adesoes.Where(b =>…
-
7
votes4
answers1423
viewsHow to build custom queries using Entity Framework?
I have an SQL Server database that is accessed via ORM Entity Framework Core, where access to a collection of products, these products are filtered through a DTO that has the terms of the search,…
-
7
votes2
answers173
viewsSearch range of numbers (string type) with Expression Lambda?
I have this data model and I don’t know how to do the instruction lambda: public class CidadeAbrangencia { [Key] public int CidadeAbrangencia_Id { get; set; } public string CEPInicial { get; set; }…