Most voted "lambda-expressions" questions
A lambda expression is an anonymous function that you can use to create delegates or expression tree types.
Learn more…305 questions
Sort by count of
-
5
votes1
answer85
viewsWhat is the Java equivalent of this Ruby lambda?
In his text on Inversion of Control, Fowler uses as an example an excerpt of code in Ruby that promotes the said principle to "invoke a bind method over the text input field that passes an event…
-
5
votes2
answers64
viewsIs expression-bodied recommended? Is there a performance difference?
The extent to which it is recommended, or even good practice to use Expression-bodied? I know that the Expression-bodied allow properties, methods, operators and other function members to have…
-
5
votes2
answers1055
viewsIf, Elseif and Else with Java 8
I would like to build a method using Java 8, replacing the conditional IF, ELSE-IF and ELSE. For this, I built a sequence of code, I do not know if it is ideal and would like to hear better opinions…
-
4
votes4
answers491
viewsHow to get the name of the property to which a lambda expression refers?
I have a lambda expression being translated into an expression tree (Expression Tree) as follows: Expression<Func<object>> expr = () => x.NomeDaPropriedade; How do I get the name of…
-
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
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
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
votes3
answers1895
viewsDynamic Query in a List
How to apply a filter to an object List generic using Lambda? I know with Reflection i can get an array with the properties names of my object and through itself Reflection recover the property of…
-
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…
-
4
votes1
answer493
viewsHow to mount SELECT in lambda C#?
I recently asked for help to assemble a SELECT to bring the price of products How to mount SELECT They gave me this solution that worked perfectly: SELECT P.PROCODIGO, P.PRONOME, H.HISPRECO FROM…
c# sql select entity-framework-6 lambda-expressionsasked 8 years, 9 months ago André Morais Martins 367 -
4
votes2
answers178
viewsHow to define a method that receives a lamppost expression?
I have a class similar to this one and I wanted the code she executed to be passed as a blank expression. class T { public: double execute(); }; For example: T t; int a = 0, b = 1;…
-
4
votes1
answer109
viewsRandom Order with Entity Framework
I would like to translate the following SQL statement to an expression lambda: SELECT TOP 1 * FROM tbPessoa order by NEWID() What do I put in OrderBy that will be accepted? var pessoa =…
-
4
votes3
answers614
viewsHow to create a custom list using data from four tables?
I have the following class: Nota { int id; int idFornecedor; int idProduto; int idClasse; } and I have the respective classes for the previous class ids: Fornecedor { int id; string descricao; }…
-
4
votes2
answers447
viewsHow to adapt / create a method that receives an anonymous class in C#
I have a method in which one of the parameters is an object of an abstract class - Objectmapper - whose purpose is to convert an object of one class into another of another class. Below, the method…
-
4
votes0
answers285
viewsService returns me cast error when consumed
I decided to make another post, since the subject is another, although in the original post, in the comments we touched on the subject, but no depth. I have that mistake:…
-
4
votes1
answer114
viewsHow to optimize this code?
Is there any faster (performative) way to compare the current value with the previous (bank) value with Entity Framework? Instead of selecting Id for Id (according to property Discount code below),…
-
4
votes1
answer90
viewsPass lambda expression on command line
I created a program to calculate the defined integral of a function, but I want to be able to run it through the terminal. #include <iostream> #include <functional> #include…
-
4
votes2
answers184
viewsHow to use the IN clause in Lambda?
A doubt arose that I thought would be easy, but the content I found could not understand. Well, here’s the thing: I have the tables "Client" and "Errosproducao_client" where they relate form 1 to N,…
-
4
votes3
answers1052
viewsHow to filter a list type Ienumerable<> through another Ienumerable<>?
How to filter a type list IEnumerable<> passing a parameter of type IEnumerable<> preferably via expression lambda or linq? Based on the filter below I expect this result: {MundoId = 0,…
-
4
votes1
answer278
viewsIterate over two List optimally - Algorithm Optimization O(n²) C#
I need to iterate over two lists and compare the values contained in both. But the way I’m doing it is taking a lot of time, because the greatness of my algorithm is O(n²), follow below more…
-
4
votes1
answer92
viewsHow can Stack expressions handle stack variables?
I’m learning C# and I’m reading about Brazilian expressions. The question is: how does it work and why does it work? public delegate void Test(); public void Foobar(ref Test del) { int var = 10; del…
-
4
votes1
answer332
viewsSwitch to lambda/Drum a foreach
I have this method with a foreach inside [Route("")] [HttpGet] [ResponseType(typeof(List<MarkupListResponse>))] public IHttpActionResult Get(int resellerId) { var catalogs =…
-
4
votes2
answers915
viewsSelecting an Item from a List<T> with index equal to the iteration value of for
How can I select an item from a list by the index, this being equal to the iteration value of a for? I tried to accomplish using LINQ, while compiling and inspecting the StringBuilder which would…
-
3
votes2
answers954
viewsFilter on Where the longest date with LINQ
As I pass the Where of this max datatransaction, ie I wish to bring the result but by the highest date. var resultado = (from ci in webDB.T_Controle_Importacao where ci.CNPJ == cnpj let dd =…
-
3
votes1
answer611
viewsError while passing Adddays in Lambda expression
In this lambda, gives me the error below, when it enters the IF: var resultado = webDB.T_ControleColetor .Where(cn => cn.CNPJ == cnpj) .Where(dt => dt.DataControle == DateTime.Now.AddDays(-1))…
-
3
votes1
answer70
viewsName of columns in web service return xml
That line gives me that mistake: if (db.T_TarefaParceiro.Max(p => p.IDTarefaParceiro) != null) The mistake The cast to value type 'System.Int32' failed because the materialized value is null.…
-
3
votes1
answer695
viewsError when calculating date difference in Entity with Linq to Entities
Before I was like this my expression: var resultado = db.T_CRM_StatusPDV .Join(db.T_PDV, t1 => t1.DE_Cnpj, t2 => t2.CNPJ, (t1, t2) => new { t1, t2}) .Where(dt =>…
-
3
votes3
answers936
viewsHTML Helpers in ASP.NET MVC 4
I saw some HTML Helpers like this: @Html.LabelFor(x => x) and @Html.LabelFor(model => model.Propriedade), however, I do not understand this parameter that I must pass, x => x, what is this?…
-
3
votes1
answer1021
viewsSelect [with aggregated functions] group by in Lambda
How do I convert the following select 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…
-
3
votes1
answer253
viewsHow to convert lambda to Expression Trees format?
How to convert that lambda: Set.Asqueryable(). Where(profile => profile.CostCenters.Select(Costcentre => Costcentre.Id). Any(Id => Ids.Contains(Id))).Tolist() Actually I managed to do even…
-
3
votes1
answer910
viewsImplement Lambda Expression TRUE, FALSE, AND, OR and NOT with Javascript
I was reading about lambda in that article and showed examples of functional programming implementing TRUE, FALSE, NOT, AND and OR with Ruby: T = lambda { |a,b| a } F = lambda { |a,b| b } display =…
-
3
votes2
answers115
viewsOrderby lambda keeps changing with every search
I have a search in lambda, in which refers information of a grid, but at each different query it changes the information of place: Indicadores = (Pegatodos().Where(f => f.STATUS == "A") .Select(x…
-
3
votes1
answer793
viewsLambda Linq Problem: LINQ to Entities does not recognize... get_Item(Int32). How to resolve?
When trying to execute the loop for (time when query is executed) is giving error in my lambda expression: var funcionarios = repository.Funcionarios .Include(x => x.Cargo) .Include(x =>…
-
3
votes1
answer965
viewsHow to simplify a foreach by a Linq expression - Lambda
Performance is not an issue in my project, I want to know a simpler and readable replacement for my foreach using Linq and Lambda (if possible). // 'DiscoVirtual' é uma classe // 'this.HDs' é um…
-
3
votes1
answer92
viewsHow to exchange terms in an Expression?
Based on the following reply in: How to Convert an Expression Tree to a partial SQL query?, I’m using a class inherited from ExpressionVisitor to try to treat some conditions in my expressions.…
-
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
votes2
answers298
viewsConvert Linq query to Dapper
In my application I have the following query: public IEnumerable<Cliente> BuscarClientePorAnoETipo(string ano, string filial, string tipoPrestacao) { var filialConvertInt =…
-
3
votes1
answer371
viewsLambda - how to use the operator || (OR) in a . Any()
What would be the correct way to implement the line below, in Lambda? ListaDeRespostasPossiveis.Any(x => x.Nome == "respostaUm" || x.Nome == "respostaDois") I saw some examples in Stack Overflow…
-
3
votes2
answers374
viewsJava lambdas are equivalent to Javascript Closures?
I started studying functional programming and I’m a little confused about these two items. My point is: Java lambdas are equivalent to Javascript Closures? If they are not, what is the difference…
javascript java lambda-expressions functional-programming closuresasked 7 years, 6 months ago Bruno Peres 1,202 -
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
answer1289
viewsForeach with Lambda does not work
I have a list of objects I want to go through, but it’s giving error and I’m not understanding why: listaAtendimento.stream().forEach(atendimentoFicha -> {…
-
3
votes2
answers2261
viewsI need to do a SUM inside Group BY in Lambda
I’m trying to create a summary report where it consists of making a GROUP BY with SUM, i want to know how I could do it in c# with lambda or hql(Nhibernate), I managed to do a GROUP BY, but I can’t…
-
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
votes2
answers74
viewsWhere is the function that a decayed lambda to pointer points to stored? How is it released?
I learned recently that I can do this: auto a = +[]{return true;}; a = +[]{return false;}; And I understood that a lambda that captures nothing can decay to a pointer for function, as confirmed by…
-
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
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, 5 months ago Italo Rodrigo 4,344 -
3
votes1
answer142
viewsLambda expressions in nested classes with multiple methods
I was reading about Ambdas and out of curiosity, I wanted to know why it is not allowed to use when the class/ interface has more than one method, which ends up forcing us to do things like below:…
-
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…