我有两个模型,一个颜色类,其中虚拟引用了一个Vendor类:
public class Colour
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string ImageSource { get; set; }
public virtual Vendors.Vendor Vendor { get; set; }
}
和Vendor类:
public class Vendor
{
[Key]
public int Id { get; set; }
public string CompanyName { get; set; }
public string Owner { get; set; }
public string Description { get; set; }
}
首先使用EF代码,颜色表的最终结果如下:
Id | Name | ImageSource | VendorId
因此,现在当我进行查询以获取Colour
的{{1}}的{{1}}时,我可以使用:
Vendor
现在,这给了我Id = 1
类的var result = _context.Colours.Where(x => x.Vendor.Id == 1).ToList();
权限,但是虚拟List
类的每个属性都为空。
我如何获得相同的结果,但正确填充了供应商对象?
我猜测(由于我有限的SQL知识)某个地方正在进行联接...