亚音速3 - SimpleRepository [英] Subsonic 3 - SimpleRepository

查看:124
本文介绍了亚音速3 - SimpleRepository的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我玩弄亚音速3的简单存储库和我打墙在了解如何处理外键...

I am playing around with Subsonic 3's simple repository and am hitting walls in understanding how to deal with foreign keys...

如果我有一个包含一个产品对象

If I have a product object containing

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;

我如何使用存储库带回所有产品的列表,包括他们的类的对象实例化?

How can I use the repository to bring back a list of all products with their category object instantiated?

目前,我已经写了LINQ查询,它加入了有关product.categoryID = category.ID这是一切都很好,但是当我.ToList()这个查询的结果,产品的分类不会被实例化。

At the moment I have written a linq query which joins on product.categoryID = category.ID which is all well and good, but when I .ToList() the results of this query, the product's Category isn't instantiated.

有没有办法做到这一点,或者我需要手动实例化范畴的每个产品?

Is there a way to do this, or do I have to manually instantiate the Category for each product?

谢谢

推荐答案

您需要得到LINQ来填充它,
使用类似
VAR的查询=从产品repo.All(产品)
            加入categoryItem在repo.All(类别)
            在product.CategoryId等于categoryItem.Id
            选择新{
              ID = product.ID,
              名称= product.name,
              说明= product.description,
              的categoryId = product.CategoryId
              类别= categoryItem
           };

you need to get linq to populate it,
using something like
var query = from product in repo.All(Product)
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
};

这篇关于亚音速3 - SimpleRepository的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆