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
-
1
votes1
answer452
viewsKnow the size of each element of a list
Assuming I have one List<byte[]> Imagens; and I want to know if any element on that list has more than 1 mega, I could do it via foreach, checking item by item: foreach (var item in Imagens)…
-
1
votes1
answer92
viewsLinq to SQL - Dynamic sort by column index
I’m using a component called datatables.js (https://www.datatables.net/) to display my tables and it owns the property Serverside, that I call, in Ajax, my list from somewhere. It sends the…
-
1
votes3
answers124
viewsUse of "Contains" in search expression
I have a string _Users of the kind List, it contains several lines. Each line consists of an integer and a string separated by comma (in general it is only one string): ID (numbers only),name…
-
1
votes1
answer58
viewsQuery and view in dropdownlist
Is giving the error below in dropdowList and do not understand why. Error: Cannot associate the 'System.Collections.Generic.List1[<>f__AnonymousType82[System.Int32,System. Stri ng]]' to type…
-
1
votes1
answer45
viewsHow to make a LINQ query that returns the amount of people who were born per month?
I would like to make a LINQ query that returns the amount of people who were born in the month. In Mysql I do this query: SELECT COUNT(*) AS DataNacimento FROM pessoas WHERE MONTH (DataNascimento) =…
-
1
votes1
answer149
viewssearch object list in Entity [LINQ]
I have a list of objects and would like to search 2 properties of that list in the database. with a list of primitive types I would do so: (from n in db.Tabela where…
-
1
votes1
answer235
viewsC# - Subselect in Lambda and Linq
How to mount the query below in Lambda and/or Linq? select emp.cd_empresa AS ID, emp.nm_razao_social + ' (' + emp.nm_fantasia + ')' AS EMPRESA, (SELECT COUNT(con.cd_consulta) from…
-
1
votes0
answers60
viewsRelate more than one column to lambda Expression
I have the query below that relates only the Processoid. I need to know how to relate processes and processes lists by Processoid and Grupoid. I have consulted in several groups and did not get an…
-
1
votes2
answers184
viewsDDD Automapper with Linq Expression
I have a problem with automapper, when I pass a parameter in Linux Express, it seems that it does not make the exchange... decimal valor = 13; var model = service.Obter(x => x.DataRegistro == new…
-
1
votes0
answers26
viewsHow to implement the "Where" clause as "in" and "not in" in c# Linq?
I have the following querys: Select * from Processos where idProcesso in (1,2,3,4,5); Select * from Processos where idProcesso not in (1,2,3,4,5); Where idProcess is a column with data type int. I…
-
1
votes2
answers1579
viewsNOT IN in Inline using a sub-query
I am using as a basis the answer in: https://stackoverflow.com/questions/432954/not-in-clause-in-linq-to-entities I need to make a query where do not contain (NOT IN) the Ids coming from another…
-
1
votes1
answer1377
viewsLinq with 2 different context using Inner Join
I would like to make a query in 2 different databases (2 Dbcontext) I tried it in several ways, one of them: I make a prequery in Dbmega context to recover the employees var FuncionariosLinq = (from…
-
1
votes2
answers1714
viewsSend a list of data in a viewbag and receive in a foreach in the view
The query data is correct, but I cannot return the data to the view. Controller: var disponib = (from d in db.Disponibilidade join c in db.Catequista on d.CatequistaID equals c.CatequistaID where…
-
1
votes1
answer87
viewsData Annotation - error ratio 1:1
I’m trying to make a 1-to-1 relationship. Apparently it would be something simple but my system is getting lost in this relationship; It doesn’t make a mistake, but the relationship is wrong: Model:…
-
1
votes3
answers236
viewsCompare two querys
I have a query that returns only the catechisms that went to the event: var catequizandosCheked = (from cat in db.Catequizando where cat.Eventos.Any(e => e.EventoID == eventoID) select new…
-
1
votes3
answers510
viewsTake class property C#
People need to take all property of a class that is of class type. Ex: public class Pessoa{ public virtual int? Id { get; set; } public virtual MinhaClasse1 prop1{ get; set; } public virtual…
-
1
votes1
answer613
viewsHow to select using LINQ with 2 tables?
This is my select: bd = new AcessoBancoDados(); bd.Conectar(); string cidade = "SELECT c.Nome FROM Cidade c join Estado e on c.EstadoId = e.EstadoId WHERE e.Sigla = '" + dto.Estado + "'"; dt =…
-
1
votes2
answers454
viewsHow to convert Float to String using LINQ for Entity?
How to convert Float to String using LINQ to Entity? I need to convert a field from my database that has the float type to the string type in my C# using the LINQ. Try using Convert.Tostring,…
-
1
votes1
answer189
viewsLINQ to SQL - Exception when giving sum() in a query that contains another subquery using LINQ
private decimal GetBankAccountCashierTotal() { var company = _context.Company.FirstOrDefault(); return _context.PersonBankAgencyAccount .Where(p => p.PersonID.Equals(company.PersonID)) .Where(c…
-
1
votes1
answer301
viewsHow to work with anonymous guy
I have the following code snippet: var filter = new { categoria = 1, cond2 = foo, ... }; p = new ProdutoBusiness().listarProdutos( filter ).ToList(); I wanted to work with this anonymous type as a…
-
1
votes0
answers118
viewsNamespace error name 'Linqtodb' could not be found
I downloaded Linq2db.Firebird via Nuget and changed the file as per the tutorial: <#@ template language="C#" debug="True" hostSpecific="True" #> <#@ output extension=".generated.cs" #>…
-
1
votes1
answer986
viewsHow to join two different lists using LINQ and Where?
I have three classes: class Cid { public string cid { get; set; } //importo esse campo via txt public string descricao { get; set; } //importo esse campo via txt } class Relacionamento { public…
-
1
votes1
answer182
viewsQuery Linq C#
Good afternoon I have the following database structure: Tables: -User -Group -Permission And all relations N to N: Grupousuario Permissaousuario Permissaogrupo I set up a query to return the user,…
-
1
votes1
answer167
viewsDoubt with Join between two classes
I have the Classes: class Procedimento { public string CodProcedimento { get; set; } public string NomeProcedimento { get; set; } public string TpSexo { get; set; } public int IdadeMinima { get;…
-
1
votes2
answers304
viewsPick all fields of a class using Lambda + Group By
I have a list: produtosCompletos = (from f in estoques join p in produtos on f.idProduto equals p.id join c in classes on f.idClasse equals c.id select new produtoCompleto() { idUnidade =…
-
1
votes0
answers130
viewsHow to use Subqueries with LINQ Entity Framework?
I need to write the following query in the Linq Entity Framework. I’m having difficulty in the subquery part, where I need to accumulate the quantity field. SELECT ppc.[PedidoCompraId] ,ppc.[EAN]…
-
1
votes1
answer670
viewsFilter with Linq or Lambda using Join and Group By
Good Afternoon In a table where it is always inserted new records may occur of having the same Date and the same Ratecode, however I want to get a list of this table but for each Date group,…
-
1
votes0
answers52
viewsSort Metrogridview content by clicking on the Heder title of a particular column
Hey, guys, I got a problem, I’ve been fighting for a while. I am using in my application Metroframework and Linq,and noticed that Metroframework does not have certain properties or that they do not…
-
1
votes2
answers75
viewsHow to make an if in a select when creating an object?
I don’t know if the title is right, but the question is this:: listaAgendaDetalhe = (from a in listaAgenda join p in listaProfissional on a.idProfissional equals p.id select new agendaDetalhe() {…
-
1
votes2
answers263
viewsHow to select the whole object, Lambda C#
I have a difficulty here in this lambda, I would like to know how I select the whole object without having to specify all its properties. Like a: SELECT * FROM Somethings Without having to specify…
-
1
votes1
answer121
viewsCapture Tracesql query in LINQ c#
I have an appointment in LINQ and I need to capture the generated sql, but I did not succeed. The conversion to Objectquery that I found does not work. What is missing? var sqlConsulta = (from a in…
-
1
votes1
answer474
viewsHow to bring other columns with Groupby with LINQ
I have two tables: 1st Process containing Processoid and Situacaoprocessoid 2nd Situationthe process that contains Situationthe Process and Description Models: public class ProcessoModel { public…
-
1
votes1
answer1012
viewsGroup objects and add values
I have a class ListaBid with several objects, in this class there are attributes Partnumber(Chave), Quantidade and SaldoPartnumber. I can have X objects with the partnumber Y and other X objects…
-
1
votes1
answer170
viewsLinq to sql with subquery
I have two tables, and would like to get only the data from table A, filtering by related table B. I would like to know how to write this query with Linq to Sql in C#. I wrote the example below in…
-
1
votes2
answers1000
viewsHow to get a list of values common to two lists with LINQ?
I have two List, the first, which is a list containing all the establishments available in the company, for example: Estabelecimento Sigla - XPTO Descricao - XPTO List Estabelecimento Sigla - RPTO…
-
1
votes1
answer38
viewslambda error with Join when placing a Groupby
In this lambda, is giving error in select in t1 and t2. If placed Key says it does not recognize Totalliquido and the fields in t2. If removed Groupby works. public List<LiberacaoItensDTO>…
-
1
votes2
answers138
viewsTolist() returning read-only
Follows code: using (var db = new Entities()) { var result = db .Tabela1 .Select(x => new { x.Coluna1, x.Coluna2 }) .ToList(); foreach (var item in result) { if (item.Coluna1 == string.Empty) {…
-
1
votes1
answer141
viewsdoubt expression Innuendo, clause IN
I have the following expression retorno = (from ven in context.VendaModel select new { ven.barras, ven.data, ven.valor }).ToList(); I need to search only what you have on a list that will be passed…
-
1
votes2
answers126
viewsHow to insert a Where into a Linux query
I have the following query: var result = (from line in db.ApadrinhamentoListas group new { line } by new { line.datahora, line.valor_doacao } into grp select new { DataHora = grp.Key.datahora, Valor…
-
1
votes0
answers153
viewsEntity Linq consultation in many-to-many relationship
I inherited a bank that is untouchable... despite having some very "strange" things. For example I have the following situation that would represent an n-n relationship but the relationship does not…
-
1
votes1
answer89
viewsError when placing SUM
I’m trying to implement the SUM within those lines of code to sum the two columns Litro and TotalGasto Code: var teste = consulta.Where(i => i.DtAbastecido >= dataInicio &&…
-
1
votes1
answer88
viewsIs it possible to create a column in LINQ?
I am trying to turn the following query into LINQ SELECT [nu_ano] ,[nu_mes] ,[id_projeto] ,[id_fase] ,'Financial Progress ("Competência")' as ds_categoria ,'Baseline' as ds_curva FROM…
-
1
votes0
answers70
viewsCast for LINQ decimal?
Since there is no Convert.ToDecimal() in language SQL, how could I transcribe a as decimal(18,2) in LINQ? I tried through the decimal.Round() but it’s not working. I have the following query on SQL:…
-
1
votes1
answer751
viewsCS0266 error Cannot convert implicitly
When trying to make a list where you will filter only the 5 largest records by values in descending order I am experiencing this error: CS0266 error Cannot convert type implicitly…
-
1
votes2
answers456
viewsString Field List Sorting
I have a List with attributes, of which I have the field of reviews, containing: Excellent, Good, Regular, Bad, and Bad. The information for this field I get from the consumption of a REST API using…
-
1
votes2
answers452
viewsLINQ (LAMBDA) How do I add another list of objects to my Where? c#
Good afternoon, I’m running a C# Net Core application, using lambda for database context handling. I have one question, and that is: I have a list of objects with these two attributes: Name and…
-
1
votes1
answer47
viewsOrderly list return at BLL?
In my project I use the EF6, use generic repositories and in my layer BLL I have the class ClienteBLL, which is a class that has the logical implementation methods of the class. In one of the…
-
1
votes3
answers277
viewsHow to concatenate sublists from a list and add values to them using Linq with C#
Hello, I have the following 2 classes: public class EstoqueItem { [Key] public int Id { get; set; } public decimal Qtd { get; set; } public Estoque Estoque { get; set;} } public class Estoque {…
-
1
votes2
answers89
viewsRename field in a lambda
In SQL I do so: select campo1 as teste from tabela And in a lambda? How would I do? I have this lambda with several tables and the field ValuePayment is repeated several times. var qry =…
-
1
votes2
answers209
viewsAdd subitems between groups with Linnus
How can I perform calculations between subsets of a group by query in English? Follow example: Consulta Linq var listPlanoDeContas = (from t in _planoDeContasRepository.GetAll() orderby t.Month…