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
-
2
votes1
answer60
viewsSumasync return zero
I have an appointment in LINQ where do I use the SumAsync, however when my entity is empty I have the exception: The cast to value type 'System.Decimal' failed because the materialized value is…
-
2
votes1
answer1235
viewshow to select Count using Linq C#
I need to convert this chunk of SQL code to Linq C#. I’ve been able to convert virtually every code. SELECT COUNT(Q.ID_QUALIFICACAO) AS CONHEC_ESPECIFICO FROM QUALIFICACAO Q INNER JOIN ATENDIMENTO A…
-
2
votes2
answers800
viewsSlow SQL LINQ C# Entity Framework problems
I am using Entity Framework, I have a list of objects (data taken from the database) with data from Clients, public virtual DbSet<clientes> clientes {get;set;} public…
-
2
votes1
answer87
viewsConvert SQL script to Linq
I need to convert the SQL script below to Linq. SELECT [ID_Pessoa], [ID_ArquivoPagamento], SUM([Peculio_Valor]) AS 'Peculio_Valor' FROM [VW_PESSOA] WHERE [ID_Pessoa] = @ID_Pessoa AND…
-
2
votes1
answer44
viewsSave Ienumerable<T> inside a parent entity with LINQ
I have the following classes: public class Foto { [Key] public int Id { get; set; } [StringLength(500)] [Required(ErrorMessage = "Obrigatório")] public string Nome { get; set; } public int Item_Id {…
-
2
votes1
answer62
viewsString search in database using Linq C# wpf
I have a bank and I want to run a search in the name field, but I also want the customer to be able to search for parts of the string or even with uppercase and minuscule letters. by the time my…
-
2
votes1
answer266
viewsSelect inside a dropdown using jquery
I can’t get the script to work. I have to do research into the second Dropdown (Scams) and save the ID of the second dropdown to make the Post the ID in the BD Controller: This Controller will seek…
-
2
votes0
answers90
viewsLINQ with Left Outer Join in Manytomany
I searched a lot about LINQ and Extension Methods, but I did not find a solution for this query that I need to do. The fact is that I have the model below (I left only the entities used) and I need…
-
2
votes1
answer1368
viewsUse of search/search filters with Entity framework
I am creating a grid with book data and I am adding some filters, the problem is time to create the filters of a table that has a link with books, I can’t navigate(Obs.:in the view I can navigate in…
-
2
votes1
answer113
viewsSubquery with Linq
I need to consult with Linq on an object called Client. This object has a relationship with another object, which is a list of phones. For each of the phones, there is a type: 'Casa', 'Comercial',…
-
2
votes1
answer160
viewsLEFT Outer Join does not work on LINQ when 0 is the reference? null only
I’m having doubts on Left Outer Join, I’m using MVC 5 C#, Net 4.5.2. I have the following Model Fornecedor public class fechamentoFornecedor { public int FornecedorId { get; set; } public int Tipo {…
-
2
votes1
answer594
viewsLinq + Lambda, sub-query, distinct and not in, how to improve this query
I had the following syntax in SQL SELECT tbl_boleto.int_IDC, tbl_Admin.int_STATUS, tbl_Admin.int_CONVENIO, tbl_Admin.int_PLANO, tbl_Admin.int_RESTRICAO, tbl_Admin.str_URL FROM tbl_boleto INNER JOIN…
-
2
votes3
answers192
viewsFormatting with UNION and LINQ in C#
I am using the following code to bring a list of companies with CNPJ formatted for Datagridview: dgv.DataSource = db.pessoajuridica .Select(d => new { d.idPessoa, d.nome, d.cnpj })…
-
2
votes3
answers216
viewsWhat are the advantages of working with Fluent Interface with LINQ?
What are the advantages of working with a fluent LINQ interface? I have that code: Employees.Cs. namespace LinqConsulta { class Empregados : List<Empregado> { public Empregados Lista() {…
-
2
votes2
answers356
viewsMerge two items of an Ilist into one item by Id
In my class has: Id Venda Devolucao I have a IList of that class, and in that IList has [0] classe Id = 100, Venda = 230.00, Devolucao = 0; [1] classe Id = 100, Venda = 0, Devolucao = 50.00; [2]…
-
2
votes1
answer119
viewsHow to get the content of a tag from a Linq query?
I have XML with the following structure: <?xml version="1.0" encoding="UTF-8"?> <pessoas> <pessoa> <nome>Joao</nome> <email>[email protected]</email>…
-
2
votes1
answer90
viewsHow to call Linq method in View?
Good morning, everyone. my question is this, I have the following method in my model: public IQueryable GetConsulta() { var q = (from c in Datacontext.Tabela1 join b in Datacontext.Tabela2 on…
-
2
votes1
answer1039
viewsSort list by a string property with number
I have an object of the type Ata where I own the property NroAta which corresponds to the number of the minutes in question, but in grid when I sort by this number, it ends up putting the numbers in…
-
2
votes2
answers100
viewsSQL query for Linq mvc4 c#
I’m not very familiar with Linq and I’m having a hard time turning this SQL query into Linq, can someone help me. I do the join of 6 tables (it wasn’t me who made the database. I have to work with…
-
2
votes1
answer63
viewsstate' cannot be Assigned to -- it is read only - Entity Framework
Follows the code: var resultado = db.Tabela .Where(l => l.Nome == "João") .Select(l => new { l.numero, l.cidade, l.estado, l.pais }); I know that in the database has "SP" value of the state…
-
2
votes1
answer95
viewsQuery using Entityframework why the performance variation?
I have the following querys using Linq to Object: _Context.GerenciaTransacao.Where(x => x.Placa == "LUN1320").ToList(); in this query, the results return in 100ms. and string placa = "LUN1320";…
-
2
votes1
answer47
viewserror left Join Linq
I cannot access the methods of a daughter class that was created using database first: namespace Dados { using System; using System.Collections.Generic; public partial class pessoa { public pessoa()…
-
2
votes2
answers1028
viewsHow to query containing MAX and COUNT via LINQ
I got the following model: public class Crm_Analise { [Key] public int id { get; set; } public string cod_item_CRM { get; set; } public string TAG { get; set; } public string data_creat { get; set;…
-
2
votes1
answer111
viewsError when performing LINQ query with equals in Where enclosure
When executing the query below: public ActionResult GridViewPartial() { if (Session["cod_cli"] != null) { int cod_cli = Convert.ToInt32(Session["cod_cli"]); //var model = db.DadosTecnicos; var model…
-
2
votes3
answers86
viewsWhy do you print the variable type instead of the result?
See the method below: public void TesteLambda() { List<String> selecoes = new List<string>(); selecoes.Add("USA"); selecoes.Add("Brasil"); selecoes.Add("Itália"); selecoes.Add("França");…
-
2
votes1
answer298
viewsHow to make a SUM in different table fields in the Entity Framework?
That’s the SQL that I have as an example, I would like to do the same with Linq? select SUM(iv.precoMediano * oi.quantidade) as total from orc_orcamentoItem oi inner join orc_insumoValor iv on…
-
2
votes2
answers123
viewsHelp with LINQ, query no . Net
Good morning, guys, I could use a little help with LINQ. I am trying to perform the following query through the: SELECT NFE_SAIDA.NFESAI_SEQUENCIA FROM CAD_NFE_SAIDA NFE_SAIDA LEFT JOIN…
-
2
votes1
answer46
viewsError when simulating distinc in query with Linq and lambda Expression
I have 2 tables in a Sqlserver bank. One tbState call and another tbCity. I am trying to return all states of the table tbState that have at least one city (tbCity) and with the properties…
-
2
votes2
answers2197
viewsWhat is the most efficient way to clear a list (List) with C#?
I have a scenario here where I create a list to check some items, and I need to clear this list inside the loop, and I got some questions regarding the performance I must check the list before I…
-
2
votes2
answers402
viewsReturn data from a Linq query to an EF Core repository
I have the Person class that relates to the Personal and Personal Tables in a one-on-one relationship. In my table Person I have the field Personnature where 0 = Person and 1 = Legal Person. A…
-
2
votes2
answers93
views -
2
votes1
answer635
viewsC# - Multiple keys in JOIN LINQ Lambda Expressions
I have an SQL as follows: SELECT * FROM KY_AR_SOLICITACAO A JOIN KY_AR_SOLICITACAO_ITEM B ON A.NF_ENTRADA = B.NF_ENTRADA AND A.SERIE_NF_ENTRADA = B.SERIE_NF_ENTRADA AND A.NOME_CLIFOR = B.NOME_CLIFOR…
-
2
votes3
answers458
viewsHow to Update to Linq?
My project has the Delete method, only it definitely deletes the table record in the database. I would like to instead of delete, change the column record, I have a field called "Status", this field…
-
2
votes1
answer181
viewsWhat is the difference between using "equals" vs == in LINQ to Entities?
As quoted above, when I say equals from LINQ to Entities I am referring specifically to the reserved word of C# and not to the Equals() of System.Object. Source: equals (Reference of C#) The…
-
2
votes1
answer44
viewsWhat is the most efficient way to obtain a property from an Entity?
I’m using the EF6 and would like to know how to get the best performance when redeeming a unique property from a Entity. Assuming the following case: Let’s say I need to fetch all the names from a…
-
2
votes1
answer165
viewsLike search with LINQ using array
Context: I have the following form: On this screen the user can filter materials by some of their properties. The filter highlighted in the image allows users to search for one or more manufacturing…
-
2
votes1
answer72
viewsError in left Join Linq - Dbcomparisonexpression requires Arguments with comparable types
I have the following method: However, when I run the query in the Log, using the left Join I get the following message : Dbcomparisonexpression requires Arguments with comparable types [HttpGet]…
-
2
votes2
answers124
viewsJunction of 2 Linq Queries
I am using the mysql database. I have 2 tables one of questions and options related to the question. For every access I make to the system I need to take the questions randomly and obviously the…
-
2
votes1
answer111
viewsSum total value of each LINQ category
I have a Shopping List(Shoppingitems) like this: Descricao: Padaria Campobelo Valor: -24.00 Data: 06-03-2019 Categoria: Alimentacao Descricao: Uber tecnologia Valor: -24.00 Data: 07-03-2019…
-
2
votes1
answer60
viewsHelp in SQL query for LINQ
I have a problem/difficulty, I have this following SQL query that I need to transform it into LINQ, but I am having problems in LINQ COUNT(). select m.id_marca, m.ds_marca,…
-
2
votes1
answer67
viewsTheninclude of a List
I have an entity called Team (image 1) which in turn has a Icollection of Userteam (image 2) which in turn has a Icollection Applicationuser called Member. Goal: return a list of Teams with their…
-
2
votes1
answer52
viewsBest way to query the database using LINQ and Entity Framework
Hello! I need to make a query in the database, the scenario is as follows: I receive email and from it I seek the id user. About the bank, there is the table Contact, which has Nxn relationship with…
-
1
votes1
answer256
viewsGet Weekday through a LINQ date
I need to get a record set of a respective day of week(Example Second), where for this I have a field in the table of type datetime. In Sql would look something like this: SELECT AVG(P.Quant) AS…
-
1
votes2
answers771
viewsBring three possible results with Lambda
I need it in one expression to bring three possible outcomes. If date is up to 15dd, returns 1, if it is between 15 and 45 dd returns 2 and if it is larger than 45 returns 3. This is my lambda and…
-
1
votes1
answer1104
viewsJoin with lambda Expression only
With LINQ no problem. Now, how do I make a join with two or more tables? Below the attempt of the join that I couldn’t go through with. Two tables(T_Acao and T_ProximaAcao). Field in join is the…
-
1
votes1
answer43
viewsWindows Mobile 5 error read XML
I am in debt to get the values of the following XML <ArrayOf xmlns="http://schemas.datacontract.org/2004/07/WcfServicePedido_v7" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <V>…
-
1
votes1
answer328
viewsSomething wrong with references using two layers in Entity
I made an example in Entity 5.0 and with 1 layer worked perfect. Now I’ve separated into UI and DAL, but this giving error. The same page that worked in the layer DAL when made in the UI is giving…
-
1
votes2
answers147
viewsUse lambda with Ado.Net
Using sqldatareader and ado.net, can you use lambda with Linq or just lambda or just Linq? This is not a multiple question, but Lynx and Lambda are always together, so the various "?" okay?
-
1
votes1
answer154
viewsBank table does not update
I have in my database some tables they already contain data saved, but I am not able to update this data. I have the method below that performs the insertion of a new item in the table if the table…
-
1
votes2
answers84
viewsIs there a LINQ method that returns a default value of my preference?
Is there any LINQ method that returns a default value of my preference, which fulfills the role of this method in a more efficient way? public static int? procurarIdPorCpf(string cpf) { using…