Last post Nov 03, 2020 03:48 AM by CopBlaster
Nov 02, 2020 07:36 AM|CopBlaster|LINK
I just uploaded my site and noticed that I get an error from the database that leaves me with no idea what the cause is. It only happens on details pages for individual posts. Every other page on the site that displays data from the database is just fine.
This is the error"
A database operation failed while processing the request.
AggregateException: One or more errors occurred. (Data is Null. This method or property cannot be called on Null values.)
SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
There are pending model changes for ApplicationDbContext
In Visual Studio, use the Package Manager Console to scaffold a new migration for these changes and apply them to the database:
PM> Add-Migration [migration name]
Alternatively, you can scaffold a new migration and apply it from a command prompt at your project directory:
> dotnet ef migrations add [migration name]
> dotnet ef database update
Nov 02, 2020 09:22 AM|DA924|LINK
I can tell you that you are trying to persist an EF entity/object to the database that has a null valued property, MS SQL Server database table column is not accepting null data for a column to be saved to the table and MS SQL Server is throwing an exception.
1) configure the table column in the database to accept null data
2) or debug your program and find out how a null value is populating a property in the EE entity/object that is being persisted to the database table
Your other error is about migrations that I avoid like the plague. I use traditional DBA tools for migrations not EF. :)
Nov 03, 2020 12:32 AM|CopBlaster|LINK
Thanks, I've narrowed it down to just posts of a specific category and that category has a table with unique values, so it must have something to do with that. I seem to recall making a certain column optional that had been required, so that is probably
it. That or maybe I am trying to get a nullable data type as non-nullable type.
Nov 03, 2020 03:48 AM|CopBlaster|LINK
Turned out there was just one entry in one table that had a null value. It was a nullable column, but required by the EF model. It's SQL Server data type is money, so somehow the null value broke a task that would get every entry from that table and then
select one based on a key value.