对象到表格的亚音速自定义映射

发布于 2024-08-14 07:01:20 字数 353 浏览 1 评论 0原文

我正在使用 Compact Framework 3.5,并暂时决定使用 Subsonic 3.0 的自定义构建来进行数据访问。问题是我习惯于开发模型优先,但也对保持对数据库模式的控制感兴趣。因此,ActiveRecord 或 Repository 似乎都不能满足我的需求,我想使用现有的 POCO 模型并将其映射到我现有的表。我习惯于通过 NHibernate 和实体框架来完成此操作。

经过一番调查后,我似乎可以编写一个自定义 QueryMapping 来为我提供我想要的自定义映射。然而,在开始这条道路之前,我希望看到一些正在完成的示例。我似乎在网上找不到任何内容,并且想知道是否有人可以提供有关 Subsonic、模型优先以及自定义每个类型表和每个层次结构表映射的经验。

I'm using Compact Framework 3.5 and have tentatively settled on a custom build of Subsonic 3.0 to do data access. The trouble is that I am used to developing model-first but am also interested in keeping control of my DB schema. Therefore, neither ActiveRecord or Repository appears to meet my needs, and I want to use my existing POCO model and map it to my existing tables. I'm used to doing this via NHibernate and Entity Framework.

After some investigation, it appears that I might be able to author a custom QueryMapping to give me the custom mapping I want. Before I start down this path, however, I'd like to see some kind of example of this being done. I can't seem to find any on the web, and wonder if anyone could give input on experience with Subsonic, model-first and a custom Table-per-Type and Table-per-Hierarchy mapping.

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

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

发布评论

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

评论(1

请持续率性 2024-08-21 07:01:20

从 SubSonic 3.0.x 开始:

如果您想使用 POCO,您非常需要存储库 - 特别是 SimpleRepository。 SubSonic 仅支持每种类型一个表的模型。 SubSonic 不支持继承。如果你想要它,你就必须对其进行编码;然而,如果你有动力去接受它,那是不可能实现的。

然而,SimpleRepository 确实提供了对模式的大量控制——即使在使用(自动)迁移时也是如此(我发现这对于 POCO-first 来说很容易上瘾)。请务必查看项目网站上的良好文档,特别是 http://www.subsonicproject.com/docs /Using_SimpleRepository。注意属性的使用。新属性很容易创建并集成到自定义存储库服务类中。

也许 SubSonic SimpleRepository 的最好一点是:它非常容易扩展。我们的团队对其进行了相当多的扩展(例如添加急切加载支持),总的来说,我们都发现它非常令人愉快。它有一个非常令人愉快的设计,速度快,重量轻,并且不会引起人们的注意。

最重要的是,SimpleRepository + Migrations 鼓励合理的模式设计。如果你发现自己正在与 SubSonic 作战,你需要检查一下自己;更有可能的是,你正在把船驶入杂草丛中。

如果您需要更强大的数据库版本控制功能,请将其与 migrator.net 结合起来,轻松实现赢。

祝你好运,欢迎来到 SubSonic!

As of SubSonic 3.0.x:

If you want to use POCOs, you very much want the Repository -- the SimpleRepository in particular. SubSonic only supports a table-per-type model. SubSonic does not support inheritance. If you want it, you'll have to code it; however, that's not of reach if you're motivated to take it on.

The SimpleRepository does, however, offer a respectable amount of control over schema -- even when using (auto)migrations (which I find quite addictive for POCO-first). Be sure to checkout the good documentation on the project site, in particular http://www.subsonicproject.com/docs/Using_SimpleRepository. Pay attention to the attribute usage. New attributes are easy to create and integrate to a custom repository service class.

Perhaps the best thing about SubSonic's SimpleRepository: it's very easy to extend. Our team has extended it quite a bit (e.g. adding eager-loading support), and overall, we all find it very enjoyable to hack on. It has a very pleasant design, it's fast, lightweight, and doesn't draw attention to itself.

Best of all, SimpleRepository + Migrations encourage a sane schema design. If you find yourself fighting SubSonic, you need to check yourself; more likely than not, you're steering your boat into the weeds.

If you need more database versioning firepower, combine it with migrator.net for an easy win.

Good luck, and welcome to SubSonic!

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