这是一个示例设置:
public class Car
{
public int CarId { get; set; }
public int? PreviousOwnerId { get; set; }
public PreviousOwner PreviousOwner { get; set; }
}
public PreviousOwner
{
public int PreviousOwnerId { get; set; }
public string Name { get; set; }
}
然后是查询:
var cars = db.Cars.Where( c => c.PreviousOwner.Name = "Stack" ).ToList();
但是,我收到一个错误,因为有些汽车有一个 null PreviousOwnerId
。内部异常读取"Unknown column 'Extent1.PreviousOwnerId' in 'where clause'"
.
注意:这是使用 .net mysql 连接器