sql - Count non null values in multiple columns with LINQ -


the following sql query counts non-null values of multiple columns in single query (as in this answer):

select count(id) total,     count(column_1) column_1_non_null_count,     count(column_2) column_2_non_null_count,     count(column_3) column_3_non_null_count,     ... mytable 

is there corresponding linq query executes sql query similar 1 (without subquery each column count)?

counting null values instead of non-null values ok.

i'm not sure exist way entity framework, think better raw sql.

but assuming want entity framework, may 1 way creating several queries using futurecount method ef.extended library. using future methods ef.extended, queries postponed until accessed result of 1 of queries , data retrieved in 1 round trip database server.

var querycolumn1 = mydbcontext.mytable.where(q => q.column1 == null).futurecount(); var querycolumn2 = mydbcontext.mytable.where(q => q.column2 == null).futurecount(); ...  int countcolumn1 = querycolumn1.value; int countcolumn2 = querycolumn2.value 

what dislike of solution readibility of code, said think approach using raw sql or using stored procedured


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -