在entity framework core中,如果兩個實體涉及到外鍵連接,查詢的時候默認是只查自身而不會去查詢外鍵表的。如果想要讓查詢結果包含外鍵實體,則需要使用include方法來讓查詢結果包含外鍵實體。如
_dbContext.ProductStandard.Include(o=>o.Product).SingleOrDefault(o => o.Id == id);
這個例子中,Product的Id和 ProductStandard的ProductId字段進行外鍵連接,想要讓查詢出來的productStandard攜帶 Product,則必須使用Include方法來進行聲明。