我正在尝试使用Subsonic 3的简单存储库,并在理解如何处理外键方面遇到了困难...
如果我有一个包含产品对象的表:
int ID;
string name;
string description;
Category category;
int categoryID (this one is just to persist the product's categoryID to the DB)
and a category object containing
int ID;
string name;
我该如何使用存储库返回一个包含所有产品及其类别对象实例的列表?
目前,我编写了一个linq查询,它在product.categoryID = category.ID上进行连接,这很好,但是当我将此查询的结果.ToList()时,产品的类别没有被实例化。
有没有办法做到这一点,或者我必须手动为每个产品实例化类别?
谢谢,
保罗