So I have this query on MSSQL where BANKS is a Table View
SELECT t.*
FROM [DB].[dbo].[BANKS] t
where t.BCODE = 'xxxxxx '; <--- with spaces
which above query has 1 result BCODE : "xxxxxx"
<--- no space
on converting it to entity framework using ToList()
or as IEnumerable()
; e.g.
var _BANKS = dbcontext.BANKS.IEnumerable();
//var _BANKS = dbcontext.BANKS.ToList();
Just note that I have to put this on a Memory
because I constantly refer to this table as reference.
On simple execution
string bankcode = "xxxxxx ".Trim();
var test = _BANKS.Where(q => q.BCODE == bankcode ).ToList(); // <--- would return me null
var test2 = from t in _BANKS where t.BCODE == "xxxxxx" select new t; <--- still null
but when I change the _BANKS
as AsQueryable();
using the same code snippet above, it would give the desired result the same on the native query (see first SQL snippet).
I'm avoiding the .AsQueryable()
because it will give me a runtime error specifically
"The specified LINQ expression contains references to queries that are associated with different contexts."
because I'm using it to constantly refer in a different DBContext's.