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
-
3
votes2
answers89
viewsDeleting items in List
Staff I have a:List<Grupos> lista = new List<Grupos>(); And I have this code var matches = lista.FindAll(x => x.Nome_Grupo.ToLower().Contains(txtFiltro.Text)).ToList(); To filter only…
-
3
votes0
answers63
viewsdoubt Linq to Sql conditions
I have a Gridview with certain products and a dropdown of quantity for each. At an event onClick, products with quantity > 0. The problem is when I have a "detailed" table, and I invoke it with…
-
3
votes2
answers79
viewsAdd CSS to the Grid Record
I’m trying to add a bold in a record on the grid, but it appears as "<b>Nome</b>" and not "Name" as it should. I’m doing it for code behind, through a LINQ Follow my method…
-
3
votes2
answers745
viewsHow to concatenate Strings into a Linq query
How do I concatenate the column Sistemas, leaving Sistema, Sistemas 2? I have this appointment Linq: var fiscalizacoesBaixadas = (from tb_fiscalizacoes_campo in _context.TB_FISCALIZACOES_CAMPO join…
-
3
votes1
answer477
viewsTurning SQL Code to LINQ
With transforming codes SQL for LINQ? Questions are in the code comments on LINQ: Code SQL: Select CL.NomeDeGuerra as Colaborador, CL2.NomeDeGuerra as Gerente, Concat(C.Codigo,'-',C.NomeFantasia) as…
-
3
votes1
answer380
viewsHow to insert values into a relational table when inserting a Row and get this ID?
I am building a program to insert data from excel files into a database. My database has this structure: Tables (and fields): Schedule (Id (PK), Starttime, Endtime, Dayweek, Roomid (FK), Classid…
-
3
votes1
answer187
viewsLinq query with Count
I’m doing a query that has some joins and a Count, but I want to do it with Linq. This is my Query. sbSQL.Append("SELECT grproj.cdgruproj as Id, grproj.dsgruproj as DescricaoGrupoProjeto, ");…
-
3
votes3
answers133
viewsWhere are the elements selected by LINQ stored?
I’m studying LINQ now and hit me a question: A LINQ that runs without the methods ToList() or ToArray() returns a IEnumerable<>, right? But a IEnumerable<> is not exactly a list/array,…
-
3
votes1
answer800
viewsHow to check if the LINQ expression does not come null
I have this expression LINQ: MaterialImage mainImage = images.First(i => i.IsMainImage == true); My problem is that images. First(i => i.Ismainimage == true) can return null if you have no…
-
3
votes1
answer49
viewsName editing is confirmed in the database but does not happen in the listing
I am editing a column of the database and so far everything goes very well, but when I load the table that contains this column using Include, simply does not update the "Chauffeur", exchange the ID…
c# asp.net-mvc entity-framework linq lambda-expressionsasked 9 years, 5 months ago Luiz Negrini 1,424 -
3
votes1
answer70
viewsCheck if multiple columns contain a value?
Query: query = query.Where(t => t.campo1.Contains(filter) || t.campo2.Contains(filter) || ......); I wonder if there is any way that I do not need to keep informing all fields of the table, do…
-
3
votes2
answers161
viewsUse Contains in an integer C# field with lambda or LINQ
I have the following expression: query = query.Where(x => x.MeuCampoInteiro.ToString().Contains(filter)); But an exception is occurring: System.NotSupportedException: 'The expression…
-
3
votes1
answer104
viewsOR in Join using Linq
I have the following tables: Tabela1 Tabela2 Tabela3 Tabela4 +----+-----------+ +----+-----------+------+------+ +----+-----------+------+------+ +----+-----------+ | Id | Descricao | | Id |…
-
3
votes1
answer781
viewsUndefined Object Reference for an object instance when trying to retrieve an element in an XML file
I’m making a mistake tormenting myself. Basically I am saving all equipment settings (RF Readers) in an XML file (Configs.xml). My goal is to retrieve the first element of all settings that have a…
-
3
votes3
answers455
viewsLINQ with JOIN and Where clause, how to do?
Good afternoon. I’m trying to make a left outer join (SQL) with LINQ, however, I’m not getting. The code of my class, is this one below. Can anyone give me a light on how I solve this? public class…
-
3
votes3
answers321
viewsPass List as LINQ expression parameter
I have a LINQ expression where the result is saved in the variable query, which is transformed into a list, this query returns a series of "RA attributes". I would like to pass this list of…
-
3
votes1
answer65
viewsDoubt in a lambda expression returning "true"
When I do that: List<Tipo1> tipo = await context.MeuMetodo.Find(x => true).ToListAsync(); What am I saying here: (x => true)?
-
3
votes1
answer234
viewsDynamic linq with C#
Inside the new in Linq. I need to create the dynamic properties based on a data table how can I do this? var query = (from indicador in tableIndicado.AsEnumerable() group indicador by…
-
3
votes1
answer157
viewsLinq groups and fetch max id
Is there any way to optimize the code below so that you search the forms that have the maximum version according to the IdCentroCusto? In the code below I’m doing the grouping and catching the…
-
3
votes1
answer931
viewsTake the highest value within the Line select
Is there any way that inside the select do linq I can take the highest value of a field of the type decimal?, according to the code below? MaxValor = Math.Max(CF.Janeiro, CF.Fevereiro, CF.Marco,…
-
3
votes0
answers67
viewsLoad information inside the lambda and use in lambda foreach
I created a property in the class CatalogItemResponse to use in a method, but Boss asked to take it. It turns out I need it to load another property and without it I’m not getting it. This is my…
-
3
votes1
answer247
viewsConvert SQL to LINQ
How do I convert the SQL below to LINQ? SELECT `clientes`.`Nome`, `clientes`.`Cpf`, `clientes`.`email`, `clientes`.`Id` as clienteId, `cartoes`.`Id` as CartaoId,…
-
3
votes1
answer221
viewsLinq - Searching for objects that have a predetermined list
I have an entity from Many-to-Many, many students for many subjects. And I need to get all students who possess all the subjects I desire. For example, subjects: Mathematics, Portuguese and Physics.…
-
3
votes1
answer96
viewsLINQ to SQL Inheritancemappingattribute Code property
What is the purpose of the property Code of the attribute InheritanceMappingAttribute? The documentation describes this way: This Property Holds a value that appears in the database table in the…
-
3
votes2
answers87
viewsC# Windows Forms Generic Object
I have a Desktop application in C# and need to load a dropdown with an option "All" and the rest coming from a database table. To load the dropdownlist I did something like this:…
-
3
votes2
answers499
viewsHow to add one more condition in a query using Linux?
How can I add one more condition to a Join ? I have the consultation below; var consultaVeiculo = (from e in dm.Tabela_SegVeiculos join r in dm.Tabela_VeiculoRefers on e.Modelo equals…
-
3
votes3
answers182
viewsLinq filttar elements of LEFT JOIN
I would like to return an object with your children, but I just wanted you to bring the children that corresponded to a certain condition. ex: I have the following classes: public class Fornecedor {…
-
3
votes1
answer132
viewsHow to simplify declaration of types with Entity Frameowrk?
I have some tables with several fields of type datetime, and for all of them I need to create a validation in Onmodelcreating() for this type, IE, I need to define .HasColumnType("datetime");, my…
-
3
votes2
answers540
viewsHow to sort with LINQ with one LIST<T> inside another?
Apparently easy but I’m not able to make a LINQ that orders two LIST that are nested. I don’t know if the word "nested" is correct. How can I do this ordering through LINQ, in the code below I…
-
3
votes1
answer666
viewsHow to make Join with more than two lists?
I have three classes: class Cbo { public string ProfId { get; set; } public string Cbo { get; set; } public string Descricao { get; set; } } class Profissional { public string ProfId { get; set; }…
-
3
votes1
answer1959
views -
3
votes2
answers106
viewsHow to dynamically generate OR comparisons with LINQ?
I have a query where I should find certain values comparing whether a column is equal to a value X. X is an array that can have 1 to 4 values. How can I in mine query with LINQ dynamically assemble…
-
3
votes0
answers57
viewsError when using dictionary in a Iqueryable.Select() method to project columns chosen at runtime
The code fragment below aims to use the Select() method to perform generic column projections in a query, according to a list of column names provided. The program works fine if all columns are…
-
3
votes1
answer110
viewsDoes "Join" make the search faster?
I have two tables, one of patients and the other of consultations. In short, the tables have the following structure: Patients int id; string nome; string cartaoSus; Consultation int id; int…
c# entity-framework linq lambda-expressions linq-to-entitiesasked 7 years, 4 months ago Italo Rodrigo 4,344 -
3
votes1
answer64
viewsI need help to transform this SQL into a LINQ
I have the following SQL: select conferencia.tb_conferencia.con_codigo, con_pedido, count(coi_codigo) as countItens, count(distinct cic_conferencia_item) as countItensConferidos from…
-
3
votes1
answer346
viewsHow to perform a Count in multiple columns?
I’d like to make a COUNT using LINQ / LAMBDA, but I’m having difficulties. Can help me? The idea is to reproduce the following query: SELECT Conta, Tipo, Documento, Nome, COUNT(0) AS Qtde FROM…
-
3
votes1
answer48
viewsHow to create a filter with all products in the second list except with products that returned in the first list
Perform a filter with the products in the second list, except those that were brought in the first list List List<string> listaProduto = new List<string>(); listaProduto.Add("Arroz");…
-
3
votes3
answers92
viewsLinq C# with order
I have a LINQ query that lists the current month’s birthday: Ramal[] RamalAniver = (from a in db.Ramais where a.sAniversario.Contains(DiaAniversario + "/" + MesAniversario) && a.bAtivo ==…
-
3
votes1
answer179
viewsMigrations, Updating a null field to not null
I am updating the phone field and CPF of my User entity that was allowing nulls to not nulls. follow the migration file public partial class Required_fild_users_cpf_phone : DbMigration { public…
-
3
votes2
answers155
viewsHow to make Where ands dynamically with Linq and Entity Framework?
How can I make the ands dynamically in the where using Linq and entityFramework? Thanks in advance for any help. return _dbContext.TbParceiro //Preciso fazer algo do tipo mas isso não funciona, não…
-
3
votes2
answers2574
viewsLINQ using function inside select new{} with lambda Expression
I am assembling a select, with the Entity Framework, which needs to "create a column" according to 4 criteria. I am trying this way: IQueryable<ImoveisDTO> Resultado = ctx.Imoveis.Select(ib…
-
3
votes1
answer4757
viewsCompare two lists of objects and pick only the different ones
I’m having trouble comparing two lists of the same kind List<Produto> in my product class I have the following structure. public class Product { public int IdProduct { get; set; } public…
-
3
votes1
answer104
viewsHow to create an Object in a Linq.Expressions.Expression and add properties dynamically to it in C#
Hi, I’m creating a library of DataAnnotations to extend Entityframeworkcore with structures that today only exist using Fluentapi. In one of them, I’m trying to recreate this block of Fluentapi:…
-
3
votes1
answer133
viewsDelete multiple database elements
I have a action [GET] delete on my Webapi. She removes one element, but would like it to remove all the elements that have a particular code. How can I change my code to remove all? My Code:…
-
3
votes1
answer75
viewsWrong Linq expression when avoiding repetitions on a List
I’m trying to avoid duplicate data before giving a set value. I have a class Player that has itself a property called NickName, this class is inserted in List. Player class: public class Player {…
-
3
votes1
answer128
viewsHow to compare two lists by property?
I have two student lists. I would like to compare them by the attribute Name, and return only the unique values of the student. In the example below, return only Aluno01.Name = "5555".…
-
3
votes3
answers92
viewsLeave date only on the datatime, without the hours part
Hello, I have a project that calls a WebApi which brings the data from the database, but one of the fields in the database is of the type DateTime and in my project, I declared as String (I can…
-
3
votes1
answer57
viewsDatatable for a class
I am a beginner in c# and right now I have some doubts about how to pass the structure of a datatable for a class to later use it, this to avoid duplicate code since I have several tables that use…
-
3
votes1
answer145
viewsLeft Join with a table does not return null value
I have this select: var pesquisa = (from p in db.Produtos join pe in db.ProdutosEmpresas on p.Id equals pe.ProdutoID into peph from pe_ph in peph.DefaultIfEmpty() select new { p.Codigo, p.nome,…
-
3
votes1
answer217
viewsHow to use denial in Contains c# with LINQ?
I need help, I’m starting in development, eclistIds returns me two ids, and if I don’t use the negation ( ! ) it returns me the id I don’t want, when I use the negation to return the other id,…