ASP.NET Core Object Reference not set to an instance for foreign key search

asp.net-core entity-framework-core

Question

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

1
0
12/6/2018 3:07:36 AM

Accepted Answer

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.

0
12/6/2018 3:14:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow