Subsonic 3 – SimpleRepository

我正在玩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; 

如何使用存储库返回实例化其类别对象的所有产品的列表?

目前我已经编写了一个连接在product.categoryID = category.ID上的linq查询,这一切都很好,但是当我.ToList()查询结果时,产品的类别没有实例化。

有没有办法做到这一点,还是我必须手动实例化每个产品的类别?

谢谢,

保罗

你需要让linq填充它,
使用类似的东西
var query =来自repo.All(产品)的产品
在repo.All(Category)中加入categoryItem
在product.CategoryId等于categoryItem.Id
选择新{
ID = product.ID,
name = product.name,
description = product.description,
categoryId = product.CategoryId
category = categoryItem
};

这篇文章似乎用亚音速来解决“急切加载”: http : //tryingthisagain.com/2007/12/03/hijacking-the-subsonic-relationship-load-process/