SubSonic 数据层返回 POCO,而不是 SubSonic 的 ActiveRecord 对象

发布于 2024-07-12 10:08:56 字数 379 浏览 11 评论 0原文

我想在我正在构建的应用程序中使用 SubSonic (2.2),因为我喜欢它的简单性,并且它可以处理我可以预见需要的任何类型的查询。 同时,我希望使应用程序的上层与亚音速类型分离。 我只想返回普通的旧 C# 对象,并传入要保存的 POCO。

但这里有一个问题:我希望我的 POCO 具有基于 FK 关系的子集合和父对象的延迟加载属性。 我想我需要以某种方式将 Subsonic SqlQuery 对象放入 POCO 上的私有成员中,并在 getter 内部使用它来获取延迟加载的属性。

关于如何使用 SubSonic 专门实现这一点有什么想法吗? 以前有人这样做过吗?

我确实意识到 SubSonic 的下一个主要版本将立即实现此功能,但这看起来至少需要几个月的时间。

I want to use SubSonic (2.2) in an application I'm building because I like its simplicity and it handles any type of query I can foresee needing. At the same time, I want to keep the upper layers of my application de-coupled from the Subsonic Types. I want to return just Plain Old C# Objects and also pass in POCOs to be saved.

But here's the catch: I want my POCOs to have Lazy loaded properties for Child collections and parent objects based upon the FK relationships. I figure I need to somehow put a Subsonic SqlQuery object in a private member on my POCO and use that internally in the getter for a lazy loaded property.

Any ideas about how to implement this specifically with SubSonic? Anyone done this before?

I do realize that the next major release of SubSonic will do this out-of-box, but that looks to be atleast a few months away.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

诺曦 2024-07-19 10:08:56

我在 SubSonic 中使用 RepositoryRecord,它“主要是”poco。 然后,我为那些在选择属性时加载其他类的类制作部分。

Partial Public Class Book

Private _Author as Database.Author 
Property Author() as Database.Author
  Get
     If _Author is nothing then
       ' Load the author class here.
     End if
     return _Author
  End get
  Set
     ....
  End Set
End Property
End Class

I use the RepositoryRecord in SubSonic which is "mostly" poco. Then I make partials for those classes that load the other class when a property is selected.

Partial Public Class Book

Private _Author as Database.Author 
Property Author() as Database.Author
  Get
     If _Author is nothing then
       ' Load the author class here.
     End if
     return _Author
  End get
  Set
     ....
  End Set
End Property
End Class
呢古 2024-07-19 10:08:56

您可以使用该属性:

tableBaseClass="RepositoryRecord"

恐怕我不知道这是如何处理延迟加载的。 您可以查看Rob Conery 的帖子 了解更多详情。

You can use the attribute:

tableBaseClass="RepositoryRecord"

I'm afraid I don't know how this handles the lazy loading though. You can see Rob Conery's post about it for more details.

嗼ふ静 2024-07-19 10:08:56

2.x 版本中没有你想要的。 您也许可以通过编辑模板来完成大部分工作(我的页面上有延迟加载属性的示例 博客)。 另一种选择是构建您的 pocos,然后构建类以从 SubSonic 生成的类和查询映射到您的模型。

What you want is not in version 2.x. You might be able to get most of the way there by editing the templates (I have examples of lazy-loaded properties on my blog). Another option is to build up your pocos then build classes to map from the SubSonic generated classes and queries to your model.

不及他 2024-07-19 10:08:56

一直想不出一个好的方法来做到这一点。 Subsonic 3 看起来非常好并且可以解决问题,但与此同时我们只是 使用NHibernate

Couldn't ever figure out a good way to do this. Subsonic 3 is looking very nice and would solve the problem, but in the mean time we just went with NHibernate.

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