EF4 +忍者+扩展方法 +存储库
我有一个带有 Category
表的 EF4.Model,它将使用 NestedSet
模式来存储子/父关系,我认为这意味着 EF4 无法帮助其工厂方法检索子项,因为不会有子项或 parentId
,只有左和右。
我创建了一个 CategoryModelExtensions
静态类,但为了检索子级,我需要一个变量来引用存储库。
但是,当静态类中不允许使用构造函数时,如何注入该变量呢?
我不想在存储库中创建 Children() 方法,因为我希望能够编写。
Category c = _repo.Get(1);
IList<Category> children = c.Children();
帮助?如果我的问题不清楚,请在这里提及,我会根据需要进行更新。
I have an EF4.Model with Category
table which will be using the NestedSet
pattern to store child/parent relation, which I think means that EF4 cannot help with its factory methods in retrieving the children becoz there will be no children or parentId
, just left and right.
I created an CategoryModelExtensions
static class, but for the children to be retrieved I will need a variable to refer to the repository.
But how can I inject that variable when constructors are not allowed in static classes?
I didn't want to create the Children() method in the repository for I want to be able to write.
Category c = _repo.Get(1);
IList<Category> children = c.Children();
Help? If my question is not clear please mention it here and I will update it as needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以直接传递它:
You could just pass it explicitly: