在下面的行中,第一行始终返回一个计数,并对每个表执行此操作。
第二行返回某些表的行,但其他表的空数据(即使是返回数据和计数的表)。 模型全部正确,EF 和 ApplicationDbContext 设置正确。
我在这里看不到任何其他明显的东西,有人能指出它可能是什么吗?
var count = _context.RequestLine.Count();
var query = await _context.RequestLine.ToListAsync();
返回错误: 数据为空。无法对 Null 值调用此方法或属性。
[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; }
}
该问题可能会导致项目中的模型与数据库中表中的结构发生冲突。在这种情况下,您尝试获取数据的其中一个表中,其中一列可能是
nullable
,同时在模型中它被表示为不可为空的属性。
例如,在您的表中,您可能有一个
bit Column1
,它具有 nullable
属性,并且同一列在数据库记录中包含空数据。同时,在模型中您可能有 bool Column1
,它在检索所需记录时不会接受任何空数据。