LINQ to Entities, which throws an exception in .NET Core, "Value cannot be null",

I am currently working on an attempt to convert our company structure from EF6 for compatibility with EF Core. I ran into a block. EF "stored procedure", which works fine on EF6, now does not work on this block of code in EF Core:

var allFolderAncestors = (from f in context.MENU_MenuFolders
                          from mtf in context.MENU_MenuToolbar_MenuFolders
                                             .Where(x => x.MenuFolderId == f.Id 
                                                      || x.MenuFolderId == f.ParentFolderId)
                                             .DefaultIfEmpty()
                          where (toolbarId == -1 
                          || (mtf == null 
                                ? false 
                                : mtf.MenuToolbarId == toolbarId)
                          ) 
                          && f.Id != 0
                          select new
                          {
                              AncestorFolderId = f.Id,
                              AncestorParentFolderId = f.ParentFolderId,
                              Id = f.Id,
                              ParentFolderId = f.ParentFolderId
                          }).ToList();

Attempting to execute this line of code results in the following exception message:

Value cannot be null. Parameter name: left

.NET Core DOES , toolbarId -1. , - OR. , . , - , ? EF Core EF6? .

+4
1

, , .

   var allFolderAncestors = (from f in context.MENU_MenuFolders
                             from mtf in context.MENU_MenuToolbar_MenuFolders
                                                .Where(x => x.MenuFolderId == f.Id 
                                                     || x.MenuFolderId == f.ParentFolderId)
                                                .DefaultIfEmpty()
                             where (toolbarId == -1 
                             || (mtf != null && mtf.MenuToolbarId == toolbarId)) 
                             && f.Id != 0
                             select new
                             {
                                 AncestorFolderId = f.Id,
                                 AncestorParentFolderId = f.ParentFolderId,
                                 Id = f.Id,
                                 ParentFolderId = f.ParentFolderId
                             }).ToList();

where OR, -,.NET Core . , - , .

+3

Source: https://habr.com/ru/post/1671723/


All Articles