代码之家  ›  专栏  ›  技术社区  ›  Paul

亚音速3-SimpleRepository

  •  6
  • Paul  · 技术社区  · 17 年前

    我正在玩亚音速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()这个查询的结果时,产品的类别没有被实例化。

    有没有一种方法可以做到这一点,或者我必须手动为每个产品实例化类别?

    谢谢,

    保罗

    2 回复  |  直到 16 年前
        1
  •  6
  •   Podge    17 年前

    你需要让Linq来填充它,
    使用类似
    var查询=从repo.all中的产品(product)
    在repo.all中加入categoryitem(category)
    在product.categoryID上等于categoryitem.id
    选择新{
    id=product.id,
    名称=product.name,
    description=产品描述,
    categoryID=product.categoryID
    类别=类别项目
    };

        2
  •  1
  •   Andrew Siemer    17 年前

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

    推荐文章