In the lines below, the first line always returns a count and does it for every table.
The second line returns rows for some tables but null data for others (even ones with data and a count returned). The models are all correct and EF and ApplicationDbContext are set up correctly.
I can see nothing else obvious here, can anyone point out what it might be?
var count = _context.RequestLine.Count();
var query = await _context.RequestLine.ToListAsync();
Error returned:
Data is Null. This method or property cannot be called on Null values.
[Table("REQUEST_LINES")]
public class RequestLine
{
[Key]
[MaxLength(30)]
public string LineLookup { get; set; } //DR01-1234567-10001
[MaxLength(30)]
public string Lookup { get; set; } //DR01-1234567
[MaxLength(12)]
public string DocumentId { get; set; }
[MaxLength(80)]
public string DocumentType { get; set; }
[MaxLength(256)]
public string DocumentDescription { get; set; }
public DateTimeOffset Created { get; set; }
public DateTimeOffset Modified { get; set; }
}
>Solution :
The problem may result in a conflict between the model in the project and the structure in the table from the database. In this case it may be that in one of the tables that you are trying to fetch the data, one of the columns may be nullable meanwhile in the model it is represented as a non nullable attribute.
For example, in your table you may have a bit Column1 that has a nullable property and this same column has null data in the records of the database. Meanwhile in the model you may have bool Column1, which it won’t accept any null data when retrieving the records required.
