具有多个数据库的 Subsonic 3.0 LINQ 模板

发布于 2024-08-23 12:43:24 字数 520 浏览 8 评论 0原文

我正在评估 SubSonic 3.0 在我们的业务中用作 POCO 对象的替代品。我是 SubSonic 的新手,昨天才安装的。我已经可以使用 3.0 LINQ T4 模板连接到一个数据库,并被能够使用 SubSonic 在一个应用程序中连接到多个数据库的承诺所吸引。

我的问题是我找不到任何有关如何将 T4 模板与多个数据库一起使用的文档(例如添加另一个连接字符串、设置 Settings.ttinclude 等)。

我在 Google 和 Stackoverflow 上搜索了答案,看看如何做到这一点,或者是否可能。任何帮助将不胜感激。


因此,我似乎能够通过向 web.config 添加另一个连接字符串,然后为该连接字符串添加第二组模板来使其工作,它可以工作,但它看起来并不“干净”,甚至真的那么干燥我。

通过添加多个 .dbml 文件,我似乎还可以使用 .NET 内置 LINQ 执行几乎相同的操作。

任何人都可以给我一些推理,为什么我们不应该只使用内置的 LINQ 支持而不是像 SubSonic 这样的第 3 方 ORM?

I'm evaluating SubSonic 3.0 for use in our business as a replacement for our POCO objects. I'm new to SubSonic, literally installing it yesterday. I've gotten to the point where I can connect to one database using the 3.0 LINQ T4 Templates, and have been wooed by the promise of being able to connect to multiple databases in one application using SubSonic.

My issue is I can't find any documentation on how to use the T4 Templates with multiple databases (e.g. adding another connection string, setting up the Settings.ttinclude etc).

I've searched Google and Stackoverflow for an answer to see how this would be done or if its even possible. Any help would be appreciated.


So I seemed to be able to make it work by adding another connectionString to the web.config, and then adding a 2nd set of templates for that connectionString, it works, but it doesn't seem 'clean' or even really that DRY to me.

It also seems that I could do almost the same thing with the .NET Built in LINQ by adding multiple .dbml files.

Can anyone give me some reasoning at this point why we shouldn't just use the built in LINQ support over a 3rd party ORM like SubSonic?

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

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

发布评论

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

评论(2

染墨丶若流云 2024-08-30 12:43:24

从亚音速邮件列表交叉发帖:

哦,是的,我一直这样做,技巧是模板的两个副本(简单)或编辑模板以迭代两组表(更难)。在第二个 settings.tt 中更改连接字符串的名称以反映其他数据库。您可能还想更改命名空间,以便在表名相同时不会发生冲突。这看起来很hacky,但我不认为这是因为它允许您独立地更改每个数据库的模板。

如果您确实只需要一组模板,最简单的方法是编辑 SQLServer.tt(或您选择的数据库)并覆盖 LoadTables 的工作方式,以便它接受一组连接而不是单个连接。我不得不说这很痛苦,而且比拥有 2 个文件副本要困难得多。

Cross posting from the subsonic mailing list:

Oh yeah I do this all the time, the trick is two copies of the templates(easy) or editing the templates to iterate over two sets of tables(harder). In the second settings.tt change the name of the connection string to reflect the other database. You might also want to change the namespace so that you don't have conflicts where table names are the same. It seems hacky but I don't think it is because it allows you to make changes to the templates for each database independently.

If you really want only one set of templates the easiest way to go about it is to edit SQLServer.tt (or your choice of database) and override how LoadTables works such that it will accept a list of connections rather than a single one. I have to say this is a pain and it is going to be much harder than having 2 copies of the files.

原谅过去的我 2024-08-30 12:43:24

(回复你的问题的答案)

现在谁能给我一些推理,为什么我不应该只使用内置的 LINQ 而不是像 SubSonic 这样的第 3 方 ORM?

立即想到:SubSonic 支持的不仅仅是 Microsoft Sql Server。

(In reply to your answer of your question)

Can anyone give me some reasoning at this point why I shouldn't just use the built in LINQ over a 3rd party ORM like SubSonic?

On immediate thought: SubSonic supports more than just Microsoft Sql Server.

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