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
-
7
votes2
answers138
viewsWhat is the Enumerable Zip in . NET?
I was making a code to combine two lists, and looking to improve discovered the method Zip of the interface IEnumerable. At first I thought it was some algorithm to "zip" a list/array/etc., but I…
-
6
votes1
answer13850
viewsJoin with three or more lambda tables
I made this expression using Lambda and 2 tables. var resultado = db.T_TarefaParceiro.Join( db.T_OsParceiro, t1 => t1.IDTarefaParceiro, t2 => t2.IDTarefaParceiro, (t1, t2) => new { t1, t2…
-
6
votes1
answer2820
viewsCompares Datetime field in a lambda only part Date
In this lambda, result will almost always be null, because I gave a Getdate() straight at the bank and when this happens, I record Date and Time. How do I make this lambda pass only Data and compare…
-
6
votes2
answers429
viewsHow to filter a list asynchronously using LINQ?
Example of code without the use of async: var products = db.Products.Where(_ => _.UserId == currentUserId); How do I make this asynchronous query taking into account that the Where of Linq does…
-
6
votes1
answer142
viewsConversion error in a query
I made this consultation and in Where is giving this error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to…
-
6
votes1
answer130
viewsTime difference in Linq
I am using Entity Framework, and I have a condition that has not worked very well: .Where(x => ((DateTime.Now - (x.DataInicio.Value == null ? DateTime.Now : x.DataInicio.Value)).TotalMinutes)…
-
6
votes2
answers1387
viewsSimplify LINQ query with Contains
I have two questions regarding the LINQ consultations below: { //lista de itens do orçamento var ids = itensOrcamento.Select(p => p.Id); //Produtos - todos produtos cadastrados var produtos =…
-
6
votes2
answers897
viewsHow to filter items that do not contain a word in a list?
I have a: List<Grupos> lista = new List<Grupos>(); And I have this code var txtFiltro = "noivas,unhas"; var palavrasFiltro = txtFiltro.ToLower().Split(','); matches = lista.Where(x =>…
-
6
votes3
answers269
viewsI need to sort a list in order that seems unusual
I have a query and want to sort this query by the attribute code. I did it as follows: consulta.OrderBy(c => c.Codigo); Result obtained: 1.01 1.A 14.04 14.11 22.01 3.04 30.01 4.01 40.02 Expected…
-
6
votes1
answer111
viewsCan LINQ be considered business rule?
Sometimes I pull active objects with LINQ expression. Utilise filtering with LINQ can be considered a business rule and in a scenario such as DDD (Domain-Driven Design)? What is the best place to…
-
6
votes1
answer2951
viewsLEFT JOIN using Linq
I have the following tables: Responsavel | Filho Id Nome | Id Nome ResponsavelId 1 Ana | 1 Aninha 1 2 Maria | 2 Ana Júlia 1 3 Pedro | 3 Mariazinha 2 I’d like to make a SELECT with INNER JOIN where…
-
6
votes1
answer185
viewsQuery Linq and see index
He wanted a query in Latin that shows the attributes of the availability table and the name of the respective catechist that is in the person table. At index will appear: Nome | AnoPastoral |…
-
6
votes1
answer140
viewsDynamically use LINQ aggregator
I am trying to create a function to use Linq aggregator functions (sum, Average, Count) and I am not succeeding. I have the following code: private double…
-
6
votes2
answers1543
viewsHow to select fields in a lambda expression query?
Through the select new from LINQ I can select which fields will be displayed in the query, for example: var subCategorias = from s in db.SubCategoria join c in db.CategoriaProduto on s.id_categoria…
-
6
votes2
answers335
viewsHow do the parameters that LINQ methods receive work?
How the parameters within these methods that receive these parameters work: <TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) An example is the method…
-
6
votes3
answers625
viewsHow to treat Nullreferenceexception with Lambda
I have a class to search for DisplayName of my entities, where I pass the entity and class returns a list with the real values and name of each attribute of the entity. My problem itself is when I…
-
5
votes3
answers844
viewsComparison of >= and <= with strings
I have a field in the database which is in the following format: YYYYMM Using the past I can normally search these fields: WHERE I.DT_INCL >= @inicio AND I.DT_INCL <= @final When trying to…
-
5
votes1
answer1589
viewsDoubt between Any and All in a lambda expression on a list
On a list, I have 12 records (hypothetical) and there is a field called ValorCampoFlag, where this field receives 1 or null, for example. If I do a validation on it and the result if there is at…
-
5
votes4
answers374
views -
5
votes1
answer186
viewsSimulate the same SQL in the Entity Framework with Linq and Lambda?
Having this data model I want to generate a SQL thus in the Entity Framework with Linq and Lambda? Support data SELECT Pessoa.PessoaId, Pessoa.Nome, Pessoa.PessoaPaiId, PessoaPai.Nome AS NomePai,…
-
5
votes2
answers213
viewsValue priority data ordering using LINQ
I have a "status" table with the following values: ID 1 = Ativo ID 2 = Novo ID 3 = Excluido How would you return a list of objects (that have the status object) prioritizing, coming first, those…
-
5
votes2
answers351
viewsUpdate data using LINQ
I read that LINQ should be used for queries, but in the context below, the best way I found to update was by using the let. var produtos = from o in orcItens join p in Produtos on o.Id equals p.Id…
-
5
votes1
answer673
viewsHow I get the sql that Linq generates by debugging VS2013
How do I get the sql that Linq generates by debugging VS2013? How do I do this? I did it and it didn’t work public static List<MontaArvoreAcao> CriarListaArvoreUn(string _uf, string _cidade,…
-
5
votes3
answers1037
viewsWhere dynamic Linq to SQL
I need to build a clause where with the field and dynamic value, for example, in pure SQL would be: WHERE :CAMPO = :VALOR However, searching the research I could not find anything specific, I’m…
-
5
votes1
answer301
viewsTwo dependent combobox using Linq to sql
How do I fill two combobox’s with Linq to sql where in a combobox for example I have countries and in another I have cities? How do they automatically change the values? I leave the image below how…
-
5
votes1
answer263
viewsHow do I sort Lambda by a List property?
I believe this has been asked before. I researched but did not find. I’m having trouble with this consultation, specifically in charge ThenBy that tries to sort the sub-list of objects. I know it is…
-
5
votes1
answer340
viewsWhat is the correct way to declare a chain of methods and prevent the same method from being used outside the scope?
In my last questions I was creating some methods to automate some queries. It’s legal, but now I need to control access to methods by specifying a sequence. When using the method Select(), i cannot…
-
5
votes2
answers296
viewsHow to make a LINQ/lambda and consume it in the view?
I have an object called Radio: public class Radio { public int RadioId { get; set; } public string StreamUrl { get; set; } public bool Ativo { get; set; } public bool Mp3 { get; set; } } I’m doing a…
-
5
votes4
answers2109
views"Filter" equal records into a list by adding their quantitative
namespace ConsoleApplication10 { class Program { static void Main(string[] args) { List<Teste> lstTeste = new List<Teste> { new Teste {Codigo = 1, Quantidade = 10}, new Teste {Codigo =…
-
5
votes1
answer219
viewsHow to simplify code with Foreach List?
How to use the ForEach() of List in the implementation below using System.Collections.Generic; public class Program { public static void Main() { List<Pessoa> pessoas = new…
-
5
votes1
answer687
viewsCould not create a System.Object type constant value. Only primitive types or enumeration types are supported in this context
I am trying to make a query in LINQ, and is returning the following error message: Could not create a System.Object type constant value. Only primitive types or enumeration types are supported in…
-
5
votes2
answers406
viewsTolist vs Typed Tolist
I was reviewing some methods of an ASP.NET MVC project and found some cases where it is used only .ToList() and others in which it is used .ToList<type>() (where type is an object type used in…
-
5
votes1
answer137
viewsConvert SQL query to LINQ
How would this SQL query convert to LINQ: "SELECT SUM(valor_negocio) valor_negocio, " + " MONTHNAME(STR_TO_DATE(MONTH(data_inicio), '%m')) mes," + " STATUS" + " FROM negocio" + " WHERE data_inicio…
-
5
votes1
answer146
viewsLINQ Lambda | Query Syntax VS Method Syntax Performance
Doubt regarding the construction and performance of querys using Query Syntax and Method Syntax / LINQ Query Syntax: var VendorQuery = from v in vendors where v.CompanyName.Contains("Toy") orderby…
-
5
votes2
answers62
viewsIs there a method of merging equal items into a var list in LINQ in C#?
Hello, good morning, good afternoon or good night, all right? I have a method that obtains products from a database using LINQ in C#, but on that list there are products that are repeated, so you…
-
4
votes2
answers144
viewsCompare Dayofweek in an ASP MVC query
I’m trying to make a query where I check if the day week is chosen to create a list of data that loads in a Viewmodel. Query: var plan = db.Servicos.Where(s => (TecnicoResp.HasValue ?…
-
4
votes2
answers1552
viewsClause in with lambda
Is it possible to have an IN clause with lambda Expression? Type: context.tabela.Where(a => a.meu_campo_id_tipo_inteiro....) let’s say one in like this: (2,3,4,5) As I put it in the dots?…
-
4
votes3
answers1073
viewsC# update XML based on another XML
Today I have the following XML structure: <ROOT> <TES IDTES="4780" IDPES="17522" /> <TES IDTES="6934" IDPES="12343" /> <TES IDTES="4781" IDPES="17523" /> <TES IDTES="6935"…
-
4
votes1
answer195
viewsGroup by with Lillo
I have the following tables: **Aula** Id Nome Data **Avaliacao** Aula_Id Aluno_Id Organizacao Didatica To get a Join of the tables I use the code: var result = from a in mdc.SBE_AA_Aulas join av in…
-
4
votes2
answers1637
viewsQuery SQL with 2 subselects for query lambda (or Linq)
select fieldA from TableA where fieldA = 459249 and fieldB in ( select FieldC from TableB where FieldD in ( select cte.FieldE from TableC cte where key= 'ABDC123' ) ) I managed to get to the point…
-
4
votes1
answer280
viewsC# Union/Order by with LINQ and Performance
Imagine the following situation there are 3 classes class A, class B, class C, class A has many classes B and many classes C. class B has many classes C. clsse C has a data datetime field. public…
-
4
votes1
answer226
viewsHow to make "OR" between Subquerys using LINQ C#
I would like to implement with LINQ C# (Using Nhibernate as ORM), the following query: return (from t1 in Session.Query<Tabela1>() join t2 in Session.Query<Tabela2>() on t1 equals t2.T1…
-
4
votes3
answers1517
viewsHow to use Skip and Take with Pagedlist Helper
I would like to make the pagination, but using Skip and Take on my LINQ not to fetch all results. Currently my code is like this: public ViewResult Index(int? page) { var grupos= from s in db.grupos…
-
4
votes1
answer1838
viewsHow to Use "Not Exists" in LINQ?
I am trying to translate the query below, in LINQ, but without success, someone can help me? SELECT * FROM PESSOAL A WHERE NOT EXISTS ( SELECT Chapa FROM PRODUCAO B WHERE B.Chapa = A.Chapa AND…
-
4
votes1
answer133
viewsError in database query with Linq
Good night! I am trying to perform a query in a mysql table, using English, and present this result in a gridview for the user. I have the table below: I’m not searching all columns of this table,…
-
4
votes1
answer152
viewsWhat would Take and Skip be in Linq?
I am doing maintenance on a system and found a GetAllQueryable(), using the method Take() and Skip(). Well, I don’t know what they are or what they’re for, I looked them up but I couldn’t find…
-
4
votes1
answer108
viewsError in . First(), as there is no selected result
In my controller of Login I use the following code to select the user if it exists, but whenever the user type the incorrect name or password, it gives an error, because it does not find the result…
-
4
votes1
answer162
viewsProblems with logic to bring data from a list or table
I did several posts here and solved almost all problems. However I understood that the problem was in the logic that I set up to bring the result. I know I’m asking a lot, but I’m trying and I…
-
4
votes2
answers268
viewsQuery by Linq and Lambda getting options range by sub-query. How to get a result closer to simple?
Given the following classes: Menuraiz: public class MenuRaiz { public MenuRaiz() { Menus = new List<Menu>(); } [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id { get; set;…
-
4
votes1
answer391
viewsHow to return concrete classes, with populated navigation properties, through Linq queries?
Following that question: Query by Linq and Lambda getting range of options by sub-query. How to get a result closer to simple? where, however, my model grew to one more class (resulting in another…