I'm trying to pull data from SQLite database with following query:
DateTime Dzien = new DateTime(ticks ?? 0);
var assinged = Data.Tasks.ToList();
var assign = assinged.Where(t => t.AssignedId ==
Data.AssignedTasks.FirstOrDefault(d => d.Date.Date == Dzien.Date).Id).ToList();
But it throws an exception:
NullReferenceException: Object reference not set to an instance of an object. PiCoreSQLite.Controllers.HomeController+<>c__DisplayClass3_0.b__0(Tasks t) in HomeController.cs, line 37
Data object is a databese contex and Tasks is a DbSet containing Tasks objects.
I tried removing ToList() but then query doesn't return anything. However it does work and returns data when using similiar query in asp.net .cshtml view:
@{
var zrobione =
from completed in Model.Item1.Where(t => t.AssignedId ==
Model.Item3.FirstOrDefault(d => d.Date.Date == DateTime.Today).Id)
group completed by completed.Categories;
}
I tried rewriting query in fluent syntax and it still throws an exception.
My question is: Why is exception thrown and how to fix it?