简体   繁体   English

如何使用新的Subsonic 3.0 IRepository模式

[英]How to use the new Subsonic 3.0 IRepository pattern

Can someone (hopefully Rob) explain how to implement the new SubSonicRepository<> Pattern? 有人(希望Rob)可以解释如何实现新的SubSonicRepository <>模式吗? I have used it with the old version and the MVC templates (in web forms) using the following initialization. 我已使用以下初始化将其与旧版本和MVC模板(在Web表单中)一起使用。

    public IRepository<StaffingPosition> _StaffingPositionsRepository;

    public  StaffingBase()
    {
        _StaffingPositionsRepository = new SubSonicRepository<StaffingPosition>();
    }
    public StaffingBase(IRepository<StaffingPosition> staffingpositionsRepo)
    {
        _StaffingPositionsRepository = staffingpositionsRepo;
    }

Note that my WCF Service inherits this class for ease of access. 请注意,我的WCF服务继承了此类,以便于访问。
Now SubSonicRepository() requires an argument of IQuerySurface and I'm not sure the best way to make this happen. 现在SubSonicRepository()需要IQuerySurface的参数,我不确定实现此目标的最佳方法。 I really dig the IRepository pattern and want to try to stick with it if possible...That is, unless anyone has better ideas. 我真的在研究IRepository模式,并希望尽可能地坚持使用它……也就是说,除非有人有更好的主意。 Thanks! 谢谢!

The templates generate a new class that implement IQuerySurface, the name of which you can configure in the main .tt file (usually something like NorthwindDb). 模板生成一个新类,该类实现IQuerySurface,您可以在主.tt文件(通常是NorthwindDb之类的文件)中配置其名称。 Usually all that is needed is to pass a new instance of this class to the repository: 通常,所需要做的只是将此类的新实例传递到存储库:

_StaffingPositionsRepository = new SubSonicRepository<StaffingPosition>(new StaffingDB());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM