6

我刚刚开始使用 Subsonic 2.2,到目前为止印象非常深刻 - 认为它会为我节省一些重要的编码时间。

在我开始全职使用它之前,虽然有些事情困扰着我,但我想解决这个问题。

在我当前的数据库(一个 SQL2008 数据库)中,我已按模式/所有者名称将表、视图、sps 等拆分为单独的块,因此所有客户表都在客户中。架构,产品中的产品。架构等,因此要从客户地址表中进行选择,我会从 customer.address 中选择 *

不幸的是,Subsonic 忽略了模式/所有者名称,只给了我基表名称。这很好,因为我在模式之间没有重复(例如 Customer.Address 和 Supplier.Address 都不存在),但我只是觉得如果我可以按模式拆分代码会更清晰。

理想情况下,我希望能够通过模式/所有者更改命名空间 - 我认为这对 SubSonic 的影响最小,但会使生成的代码更易于阅读。

问题是,我已经爬遍了 Subsonic 的源代码并且不知道如何做到这一点(我在 VB 而不是 C# 中编码并没有帮助 = 是的,我知道,责怪 ZX Spectrum !!)

如果有人以前解决过这个问题或对如何解决它有想法,我将非常感激,

提前致谢。

埃德

4

4 回答 4

6

我也打算建议多提供者方法。但是很多管道已经处于亚音速的所有权状态。如果您在 CS_ClassTemplate.aspx 中编辑几行,您可以为每个所有者配置文件创建一个命名空间。将第 58 行(我使用的是 v2.1)更改为

namespace <%=provider.GeneratedNamespace%><%=owner%>

所有者在哪里

string owner = "." + tbl.SchemaName;
if(owner == ".dbo")
  owner = "";

你把它放在上面,大约第 14 行。这样你可以为每个所有者都有一个命名空间,例如:Northwind.Suppliers、Northwind.Customers 等。我将 dbo 保留为 Northwind,因此所有测试都无需进行大量编辑即可编译。我运行了一个简单的选择查询,我认为它会按照您想要的方式工作。

于 2009-04-16T08:39:31.253 回答
3

您也可以使用我们的 t4 模板在 3.0 中执行此操作(但仅适用于 3.5)。这是一个非常好的反馈——也许我们应该默认构建它!

很高兴你在这里得到一些帮助。

于 2009-04-16T18:10:22.937 回答
1

Just to let you know I have this now working - or at least, compiling! :-) To get the owner solution to work fully though you'll need to make more changes to the Class Template as otherwise the table/key functions sit within the wrong namespace.

I've also hacked around with the stored procedure template. I couldn't (in the short time I have) work out how to split into separate files/namespaces for each owner so instead i've prefixed each sp function with the owner and an underscore.

However, just in case you have the same problem you'll know its possible to fix.

Ed

于 2009-04-16T10:47:22.890 回答
1

您可以尝试使用具有相同底层数据库连接的单独提供程序,如下所示:

<SubSonicService defaultProvider="DBData">
<providers>
<clear/>
     <add name="DBData" type="Subsonic.SqlDataProvider, SubSonic" connectionStringName="LocalSqlServer" generatedNamespace="DBData" includeTableList="table_a,table_b" spStartsWith="app,get,set" viewStartsWith="v_" />
     <!--CMS Provider-->
     <add name="CMS" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="LocalSqlServer" generatedNamespace="CMS" stripTableText="CMS_" includeTableList="CMS_Content,CMS_Page" useSPs="false"/>
</providers>
</SubSonicService>

我认为您不能以这种方式将架构本身用作键,但您至少可以通过组合 includeTableList 和 generatedNamespace 来解决这个问题。你说你在不同的模式中没有重复的表名,所以它可能会起作用。

于 2009-04-16T07:53:16.077 回答