Hello,
I am using EF Core to execute SQL Stored procedure. I am getting below Null error when i make Web api call. I am handling Nulls for all my model fields. (Example: public DateTime? EffectiveDate { get; set; } ) Let me know the fix.
Error message:
Microsoft.EntityFrameworkCore.Query: Error: An exception occurred while iterating over the results of a query for context type 'DataAccess.Ef.Context.ProductContext'.
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at Microsoft.Data.SqlClient.SqlBuffer.ThrowIfNull()
at Microsoft.Data.SqlClient.SqlBuffer.get_String()
at Microsoft.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at lambda_method62(Closure, QueryContext, DbDataReader, Int32[])
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.MoveNext()
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at Microsoft.Data.SqlClient.SqlBuffer.ThrowIfNull()
at Microsoft.Data.SqlClient.SqlBuffer.get_String()
at Microsoft.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at lambda_method62(Closure, QueryContext, DbDataReader, Int32[])
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.MoveNext()
Exception thrown: 'System.Data.SqlTypes.SqlNullValueException' in Microsoft.EntityFrameworkCore.Relational.dll
Exception thrown: 'System.Data.SqlTypes.SqlNullValueException' in System.Private.CoreLib.dll