EasyData: System.NullReferenceException: „Object reference not set to an instance of an object.”
Error:
System.NullReferenceException: „Object reference not set to an instance of an object.”
Models;
namespace Lib.Culture.Models
{
public class Country
{
public int Id { get; set; }
public string Name { get; set; } // Nazwa kraju Wielka Brytania
public Language Language { get; set; } // Język jaki jest używany
public string ShortName { get; set; } // Krótka nazwa kraju, np uk
public string Currency { get; set; } // Waluta, np USD, PLN etc
public string CurrencySymbol { get; set; } // Symbol, np $, zł
public string DateFormat { get; set; } = "DD-MM-YYYY"; // Format daty, DD-MM-YYYY
public bool LeftToRight { get; set; } = true; // Tekst od lewej do prawej (Arabia ma np od prawej do lewej)
}
}
namespace Lib.Culture.Models
{
public class Language
{
public int Id { get; set; }
public string Name { get; set; }
public string ShortName { get; set; }
}
}
Console log:
[18:19:09 INF] Executing endpoint '/EasyData'
[18:19:09 INF] Route matched with {page = "/EasyData", action = "", controller = ""}. Executing page /EasyData
[18:19:09 INF] Executing handler method Crud.Pages.EasyDataModel.OnGet - ModelState is Valid
[18:19:09 INF] Executed handler method OnGet, returned result .
[18:19:09 INF] Executing an implicit handler method - ModelState is Valid
[18:19:09 INF] Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
[18:19:09 INF] Executed page /EasyData in 35.0154ms
[18:19:09 INF] Executed endpoint '/EasyData'
[18:19:09 INF] Request finished HTTP/1.1 GET http://localhost:5021/easydata - - - 200 - text/html;+charset=utf-8 94.8274ms
[18:19:09 INF] Request starting HTTP/1.1 GET http://localhost:5021/api/easydata/models/__default application/json -
[18:19:09 INF] Executing endpoint 'EasyData API'
[18:19:09 INF] Entity Framework Core 6.0.1 initialized 'CultureContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.1' with options: None
[18:19:09 INF] Executed endpoint 'EasyData API'
[18:19:09 INF] Request finished HTTP/1.1 GET http://localhost:5021/api/easydata/models/__default application/json - - 200 - application/json;+charset=utf-8 111.8068ms
[18:19:11 INF] Request starting HTTP/1.1 POST http://localhost:5021/api/easydata/models/__default/sources/Country/fetch application/json 42
[18:19:11 INF] Executing endpoint 'EasyData API'
[18:19:11 INF] Entity Framework Core 6.0.1 initialized 'CultureContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.1' with options: None
[18:19:11 INF] Executed DbCommand (9ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT_BIG(*)
FROM [Culture_Country] AS [c]
[18:19:11 WRN] The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.
[18:19:11 WRN] The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.
[18:19:11 INF] Executed DbCommand (2ms) [Parameters=[@__p_0='?' (DbType = Int32), @__p_1='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SELECT [c].[Id], [c].[Currency], [c].[CurrencySymbol], [c].[DateFormat], [c].[LanguageId], [c].[LeftToRight], [c].[Name], [c].[ShortName]
FROM [Culture_Country] AS [c]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY
What did I do wrong? I am using ef core and .net 6 I find it works fine when there is no relationship
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (1 by maintainers)
Hello,
We’ve published version 1.4.1-rc02.
The real problem was in shadow properties in model classes, those ones in particular that are created automatically for navigation properties.
For example, when we define the following model class:
Entity Framework creates a shadow property
LanguageId
automatically for the Culture entity.Unfortunately, with the current implementation of the Fetch procedure, we can’t get the values for shadow properties, so we just hide them and corresponding navigation properties. This fix is available in 1.4.1-rc02.
If you need to give your users a possibility to define such connections (like Language in our example) you will need to add the corresponding foreign key property explicitly: