Questions tagged as 'linq'

3
answers

I need to sort a list in order that seems incoum

I have a query and I want to sort this query by the code attribute. I did this: 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 result: 1.01 1.A 3.04 4.01 14.04 14.11 22....
asked by 19.12.2016 / 20:34
3
answers

How to handle 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 actual values and name of each entity attribute. My problem is when I search, and some attribute in the entity does not...
asked by 25.04.2017 / 03:43
3
answers

How to change the structure of a LINQ query at runtime?

I have the following example of a program that implements the EF (Entity Framework). The bank and application structure is defined as follows: Table Pessoa : Primary key field: id_pessoa Field name: nome Field age:...
asked by 27.05.2016 / 01:17
2
answers

How to filter a list asynchronously using LINQ?

Code sample without using async: var products = db.Products.Where(_ => _.UserId == currentUserId); How do I make this query asynchronous taking into account that Where of Linq does not support the use of await ?     
asked by 16.09.2014 / 18:05
2
answers

Convert string to DateTime in LINQ

I have a model where all fields are string . I want to convert to DateTime and Double For this I created a new model public class CPUStats { public DateTime Data { get; set; } public Double? Disco { get; s...
asked by 16.03.2016 / 14:41
2
answers

list.foreach vs foreach

I have a list with several string , there is a difference between scrolling the list values: This way: ListaString.ForEach(delegate(string str) { Console.WriteLine(str); }); Or this: foreach(string str in ListaString) { C...
asked by 06.08.2015 / 14:01
2
answers

Filter items that do not contain words in my list

I have a personal: List<Grupos> lista = new List<Grupos>(); And I have this code var txtFiltro = "noivas,unhas"; var palavrasFiltro = txtFiltro.ToLower().Split(','); matches = lista.Where(x => !palavrasFiltro.Contains(...
asked by 12.05.2016 / 16:50
2
answers

Simplify LINQ Query with Contains

I have two questions regarding LINQ queries below: { //lista de itens do orçamento var ids = itensOrcamento.Select(p => p.Id); //Produtos - todos produtos cadastrados var produtos = Produtos.Where(p => ids.Contains(p...
asked by 31.12.2015 / 21:36
1
answer

The entity or complex type '*' can not be constructed in a LINQ to Entities query

I can not do this? public List<Filial> GetAll() { //Mostra todos os registros incluindo os desativados para os Administradores var ret = _db.Filiais.AsNoTracking() .Where(e => e.Visible) .Orde...
asked by 07.02.2017 / 15:48
1
answer

Compare DateTime field in a lambda only part Date

In this lambda, the result will almost always be null, since I gave a GetDate () right in the bank and when this happens, I record Date and Time. How do I make this lambda pass only date and compare with DateTime.Now just the date? I tried to us...
asked by 02.06.2014 / 20:12