Lambda in related classes (EF Migrations)

Asked

Viewed 24 times

0

It’s been a while since I’ve dealt with FE so I doubt it. Have the classes Product and Producthow much and need to make an inquiry in the products with quantity equal to 10;

I tried to:

var retorno = controle.Produto.Where(x => x.ProdutoQuantidade.Total.Equals(10)).toList();

However it already gives error in the ". Total", it does not find any property of the class Productoquantidade

[EDITED] I mentioned that it was above 10 by mistake, the problem is not the Equal but was not finding the class properties. I already managed to solve:

var retorno = controle.Produto.Where(x => x.ProdutoQuantidade.Any(y => y.Total == 10)).ToList();

thank you [EDITED]

  • if you can put the classes Produto and ProdutoQuantidade? and in place of Equals place == 10

1 answer

0

Assuming that the Total property is INT and should be above and not equal to 10 the expression should be like this.

var return = control.Product.Where(x => x.ProductQuantidade.Total > 10 ).toList();

or

var return = control.Product.Where(x => x.ProductQuantidade.Total >= 10 ).toList();

Equals is used to compare objects and not the value itself, has an article explaining in more detail the difference between one and the other.

http://www.macoratti.net/18/06/c_fund1.htm

  • I appreciate the attention but the problem wasn’t What. I already found the solution

Browser other questions tagged

You are not signed in. Login or sign up in order to post.