使用数据存储库模式的实体框架 - DeepLoading
我一直在实现一个新项目,我决定使用存储库模式和实体框架。
我已经成功实现了基本的 CRUD 方法,并且没有转移到我的 DeepLoads 上。
从我能找到的所有示例和文档中,我需要调用这样的方法:
public Foo DeepLoadFoo()
{
return (from foobah in Context.Items.Include("bah").Include("foo").Include("foofoo") select foo).Single();
}
这对我不起作用,也许我太懒了,但我想要实现的目标是:
public Foo DeepLoadFoo(Foo entity, Type[] childTypes)
{
return (from foobah in Context.Items.Include(childTypes).Single();
}
有这样的可能吗,还是我坚持使用 include.include.include.include ?
谢谢
I have been implementing a new project which I have decided to use the repository pattern and Entity Framework.
I have sucessfuly implemented basic CRUD methods and I have no moved onto my DeepLoads.
From all the examples and documentation I can find to do this I need to call something like this:
public Foo DeepLoadFoo()
{
return (from foobah in Context.Items.Include("bah").Include("foo").Include("foofoo") select foo).Single();
}
This doesnt work for me, maybe I am trying to be too lazy but what I would like to achieve would be something along the lines of this:
public Foo DeepLoadFoo(Foo entity, Type[] childTypes)
{
return (from foobah in Context.Items.Include(childTypes).Single();
}
Is anything like this possible, or am I stuck with include.include.include.include?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此博客帖子提到实体框架 ObjectContext 拥有有关实体及其属性的所有元数据。因此,也许您可以使用该元数据来遍历实体的属性及其子属性等。
换句话说,我相信您应该能够使用元数据自动对您的询问。
This blog post mentions that the Entity Framework ObjectContext has all the metadata about entities and their properties. So maybe you can use that metadata to walk the properties of your entity, and their child properties, etc.
In other words, I believe you should be able to use the metadata to automatically compose
Include
calls on your query.