使用数据存储库模式的实体框架 - DeepLo​​ading

发布于 2024-09-01 22:40:19 字数 548 浏览 5 评论 0原文

我一直在实现一个新项目,我决定使用存储库模式和实体框架。

我已经成功实现了基本的 CRUD 方法,并且没有转移到我的 DeepLo​​ads 上。

从我能找到的所有示例和文档中,我需要调用这样的方法:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-09-08 22:40:19

博客帖子提到实体框架 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文