0
I have a list typed in C# and I need to search for an item through several filters. I demonstrate in codes:
List<LoteRecla> listLoteRecla = new List<LoteRecla>();
I tried using the method . Exists() filtering through only one field of this list, as below and worked normally.
if (!listLoteRecla.Exists(x => x.est_lote.Equals(dtDados.Rows[i]["est_lote"].ToString())))
But I was asked to use more filters, I tried to do it the way below:
if (!listLoteRecla.Exists(
x => x.est_lote.Equals(dtDados.Rows[i]["est_lote"].ToString()) &&
x.id_log_unidade.Equals(dtDados.Rows[i]["id_log_unidade"]) &&
x.id_log_unid_local.Equals(dtDados.Rows[i]["id_log_unid_local"]) &&
x.loc_rua.Equals(dtDados.Rows[i]["loc_rua"]) &&
x.loc_num.Equals(dtDados.Rows[i]["loc_num"].ToString()) &&
x.loc_altura.Equals(dtDados.Rows[i]["loc_altura"].ToString()) &&
x.id_log_produto.Equals(dtDados.Rows[i]["id_log_produto"]) &&
x.id_log_produto_emb.Equals(dtDados.Rows[i]["id_log_produto_emb"])))
{
However this way is not working, I pass for equal data and should not enter the IF, but is entering.
Am I doing something wrong? Is there any other way to do this that I need?
Thank you.
Put one by one and see which causes a change. Maybe you are finding an unexpected value. Maybe you are using a wrong condition. You can’t know without access to your data. That is, you have to debug the code to find out what is happening. Evaluate the expressions in Debugger when you get to this point, make sure everything is according to what you expect. It may even be that the code has something wrong but we have no way of knowing.
– Maniero
ok, I’ll go adding one by one to test. Thank you.
– Rafael Oliveira