Closed rubenalves closed 3 years ago
what is 'query' variable? pls post the entire snippet from start
var query = _session.EntitySet< IProcesso >(); var query2 = _session.EntitySet< Ifornecedor >(); query = query.Where(c => c.Concluido = true);
if (!string.IsNullOrEmpty(Fornecedor)) { var str = Fornecedor.Split(' '); query2 = str.Aggregate(query2, (current, s) => current.Where(c => c.Assunto.Contains(s))); var listFor = query2.ToList(); foreach (var fornecedor in listFor) { query = query.Where(c => c.Fornecedores.Any(t => c.Id == fornecedor.Id)); }
var lista = query.ToList();
}
Fornecedor is a string variable I am tring to get a list of IProcesso
what 'listFor' contains after execution of query2? what's the meaning of foreach loop - you add multiple WHERE conditions, they will all be AND-ed, so you look for containing every matching Id?
listFor contais a list if iFornecedores where the field Assunto contains the text in string variable Fornecedor.
i am trying to get a list of all iPrecesso where the iProcesso. Forcedores has Any Fornecedor in listFor
I use this alot with Sql Server and it works fine, this i am using SqlLite in a little app, can it be a problem of sqllite?
so when you step thru in debugger, listFor is not empty and has some entities, so the query executed successfully? as for for each loop, I do not think it is correct; again, you are AND-ing all conditions, so you are trying to find recs that contain ALL related recs. Yes, it might be problem with SQLite differences, I am just not sure what diff/problem it is
in the last statement, 'var lists = query.toList();' - stop there, check what query contains, and what it returns (what's in 'lists' after execution). What does this mean 'it does nothing', something should be returned? Edited: also after execution check session.LastCommand.CommandText, what's the last SQL
in debug it simply does nothing, ends the debug and dos not pass over query.ToList(), i will tri something diferent.
I get it to work, it was not the best way to do it but it is a very small application and it is woking now. Thanks for your time .
I am trying to do this
if (!string.IsNullOrEmpty(Fornecedor)) { var str = Fornecedor.Split(' '); query2 = str.Aggregate(query2, (current, s) => current.Where(c => c.Assunto.Contains(s))); var listFor = query2.ToList(); foreach (var fornecedor in listFor) { query = query.Where(c => c.Fornecedores.Any(t => c.Id == fornecedor.Id)); } var temp= query.ToList(); } the application simpli does nothing, var temp= query.ToList(); does not throw a error but the query is not executed.
Is there a correct way to do this kind of query? Thanks.