I have these queries. The first initialData gets a list of Ids without a filter and the second query filters out the results based on user inputs. FieldId and CategoryId are foreign/primary keys of their own table. The issue is when the application first loads, nulls are sent through and thats acceptable. However when it reaches the second query, I get the Object Reference not set to an instance error.
Is there such thing as a null text identifier in .net core/c#?
var initialData = (from item in dbContext.DocumentCategories
join df in dbContext.DocumentFields
on item.Id equals df.DocumentCategoriesId
join dfs in dbContext.DocumentFieldsStore
on df.Id equals dfs.DocumentFieldsId
select new SearchDocumentsListViewModel
{
CategoryId = item.Id,
DocumentId = dfs.DocumentsId,
FieldId = df.Id
})
.ToList();
initialData = initialData
.Where(u => u.CategoryId.Contains(CategoryId) &&
u.FieldId.Contains(FieldId) &&
u.Data.Contains(FilterInput.Data))
.ToList();
I have also discovered that when I put "0" as the value, the same error triggers but if I put something like "abc", it goes on fine.
NOTE: I use GUIDs for my Ids
It's very difficult to answer but based on the information that you have provided.
It looks like in the first data load in "initialData" you forgot to initialize "Data" property.