Filtering by Where clause only when condition is not null
Tag : chash , By : dyarborough
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Since Linq is lazy it does not matter if you have "one big statement" or multiple, as long as you don't execute your query (e.g. by iterating over the results or forcing eager execution using ToList()) there is no penalty since you are just chaining extension methods. In this regard I would focus on readability. There are things to consider though, e.g. sorting cannot be lazy (you have to look at all items before you can spit out the items in order) - that's why you should always put your Where filter before your OrderBy so you have less items to sort. This said I would restructure your code like this: // get all errors
var viewModel = _errorsRepository.Errors;
// optionally filter
if (!String.IsNullOrEmpty(searchError))
{
string searchErrorMatch = searchError.Trim().ToLower();
viewModel = viewModel.Where(e => e.Message.ToLower().Contains(searchErrorMatch));
}
//order and project to ErrorViewModel
viewModel = viewModel.OrderByDescending(e => e.TimeUtc)
.Select(e => new ErrorViewModel
{
ErrorId = e.ErrorId,
Message = e.Message,
TimeUtc = e.TimeUtc
}).ToList();
|
List Collection Filtering using Where condition giving null values
Tag : chash , By : Eugenio
Date : March 29 2020, 07:55 AM
help you fix your problem I am getting the Values from DataBase View Table using the EDM Query as IList Type. , This code (reformatted to avoid scrolling): IList<EFModel.EntityModel.vwGetActiveEmployee> managerlist
= activeEmployeelist.Where(p => p.IsManager == 1)
.Select(p => p)
as IList<EFModel.EntityModel.vwGetActiveEmployee>;
IList<vwGetActiveEmployee> managerlist =
activeEmployeelist.Where(p => p.IsManager == 1)
.ToList();
|
hive queries is giving wrong result for a condition is not null with many or conditions
Date : March 29 2020, 07:55 AM
it helps some times You mentioned you used "or" instead of "and" in your query. So you did "(not A) or (Not B)" which is equivalent to "not (A and B)". This will require both to be null. This is different than "not (A or B)" which is the same as "(not A) and (not B)" which is how I wrote the query below. See De Morgans laws for a further explanation. If you want to select all rows that have non nulls then do this: select col1, col2, col3 from table
where col1 is not null and col2 is not null and col3 is not null;
Select col1 .... where col1 != '';
Select col1 .... where length(col1) > 0;
|
Postgre SQL ignore the filtering condition if the value is null
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can keep arguments as dict and send to filter() method only those of them which are not equal to None: arguments = {"A_name": A, "B_name": B, "C_name": C}
arguments_without_null = {k: v for k, v in arguments.items() if v is not None}
queryset = User.objects.values().filter(**arguments_without_null)
|
Hive, SQL: Return COUNT of NULL values for each of 100+ columns in a Hive table
Tag : sql , By : user158220
Date : March 29 2020, 07:55 AM
|