If you are trying to read some nullable data from the database, but your type is not nullable you can get this error.
If MyInt
is nullable in the database and you have this entity:
public class MyEntity
{
public int Id { get; set; }
public int MyInt { get; set; }
}
You will get the exception: System.Data.SqlTypes.SqlNullValueException: 'Data is Null. This method or property cannot be called on Null values.'
To fix this, just change the type of your MyInt
property to Nullable<int>
or int?
:
public class MyEntity
{
public int Id { get; set; }
public int?MyInt { get; set; }
}
Similar Posts:
- [Solved] EF An error occurred while updating the entries. See the inner exception for details.
- SQL Error: 1064, SQLState: 42000 [Three Methods to Solve]
- [Solved] Mybatis error: attempted to return null from a method with a primitive return type (int)
- [Solved] JAVA:java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcodbcDrive
- Vue Error: Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in
- Request failed with status code 500 & Self referencing loop detected for property ‘xx‘ with type
- org.hibernate.PersistentObjectException: detached entity passed to persist encountered by jpa
- [Solved] Sping controller Receives list entity parameter Error: nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
- Program error: the table or view does not exist [Solved]
- Android WebView monitors and rewrites window.history.go (- 1) method call