I am trying run the following script in code. Note that only LINQ query in LINQPad has no problem and generating the expected results.
var zzz = (from aa in _DBService.AvailableStocks
join bb in _DBService.UserSelectedStocks.Where(c => c.UserID == UserID)
on aa.StocksID equals bb.StocksID into newgroup
from cc in newgroup.DefaultIfEmpty()
select new
{
StocksID = aa.StocksID,
Stock = aa.Stock,
UserID = (cc.UserID == null ? "Null" : cc.UserID.ToString()),
UserStockID = cc.UserStockID.ToString() == "" ? "Null" : cc.UserStockID.ToString(),
StockID = (cc.StocksID == null ? "Null" : cc.StocksID.ToString())
}).ToList();
The error is
An exception of type 'System.NullReferenceException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Any help
Shahzad