我正在使用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()这个查询的结果时,产品的类别并没有被实例化。
有没有办法做到这一点,或者我必须手动实例化每个产品的Category?
谢谢,
保罗
发布于 2009-07-24 10:41:32
你需要让linq来填充它
使用像这样的东西
var查询=来自repo.All中的产品(产品)
join categoryItem in repo.All(Category) on product.CategoryId equals categoryItem.Id select new { ID = product.ID, name = product.name, description = product.description, categoryId= product.CategoryId category = categoryItem };https://stackoverflow.com/questions/1176594
复制相似问题