我试图使用efcore 2.1执行一个简单的选择查询,并且输出窗口引发多个异常
“抛出的异常:System.Linq.Expressions.dll中的'System.ArgumentException'”
,但最终将运行查询。是什么原因造成的?
这种情况仅在我包含多个相关实体时才会发生,例如前两个查询将毫无问题地运行,但最后一个查询将在输出中引发异常。
var a = _projectDbContext.Tasks.Where(x => x.Id == taskId)
.Include(x => x.TaskType)
.FirstOrDefault();
var b = _projectDbContext.Tasks.Where(x => x.Id == taskId)
.Include(x => x.TaskStatus)
.FirstOrDefault();
var c = _projectDbContext.Tasks.Where(x => x.Id == taskId)
.Include(x => x.TaskType)
.Include(x => x.TaskStatus)
.FirstOrDefault();
我的实际查询多次抛出这些异常,从而降低了执行速度。
public partial class Tasks
{
public Guid Id { get; set; }
public string TaskName { get; set; }
public string TaskDescription { get; set; }
public Guid? TaskTypeId { get; set; }
public Guid? TaskStatusId { get; set; }
public TaskStatus TaskStatus { get; set; }
public TaskTypes TaskType { get; set; }
}
public partial class TaskTypes
{
public TaskTypes()
{
Tasks = new HashSet<Tasks>();
}
public Guid Id { get; set; }
public string TypeName { get; set; }
public ICollection<Tasks> Tasks { get; set; }
}
public partial class TaskStatus
{
public TaskStatus()
{
Tasks = new HashSet<Tasks>();
}
public Guid Id { get; set; }
public string StatusName { get; set; }
public ICollection<Tasks> Tasks { get; set; }
}