var ch = _context.xxtu_nintex_emp_data_v
.Where(o => o.LOGIN_USER_NAME ==userId.ToUpper())
.Select(emp => new
{ OTHERMOBILENO = emp.OTHERMOBILENO ?? "" })
.ToList().SingleOrDefault();
the result is

when use toList() I get what I want but it is so slow
var ch = _context.xxtu_nintex_emp_data_v.ToList()
.Where(o => o.LOGIN_USER_NAME ==userId.ToUpper())
.Select(emp => new
{ OTHERMOBILENO = emp.OTHERMOBILENO ?? "" })
.ToList().SingleOrDefault();
the result is

I use code first approach api and Microsoft.EntityFrameworkCore
CodePudding user response:
Some things you could try
Call
ToListafter the condition, to only fetch a subset of data from the Databasevar ch = _context.xxtu_nintex_emp_data_v .Where(o => o.LOGIN_USER_NAME == userId.ToUpper()) .ToList() //<-- here .Select(emp => new { OTHERMOBILENO = emp.OTHERMOBILENO ?? "" }) .ToList().SingleOrDefault();Move the
Selectafter the LastToListcallvar ch = _context.xxtu_nintex_emp_data_v .Where(o => o.LOGIN_USER_NAME == userId.ToUpper()) //<-- re-arrange ToList/Select .ToList() .Select(emp => new { OTHERMOBILENO = emp.OTHERMOBILENO ?? "" }) //<-- .SingleOrDefault();Re-arrange it a bit more
var emp = _context.xxtu_nintex_emp_data_v .Where(o => o.LOGIN_USER_NAME == userId.ToUpper()) .SingleOrDefault(); var ch = new { OTHERMOBILENO = emp?.OTHERMOBILENO ?? "" };
