Subsonic - 如何使用 SQL 架构/所有者名称作为命名空间的一部分?
我刚刚开始使用 Subsonic 2.2,到目前为止印象深刻 - 认为它会节省我一些认真的编码时间。
在我开始全职使用它之前,尽管有些事情困扰着我,我想解决一下。
在我当前的数据库(SQL2008 数据库)中,我已按架构/所有者名称将表、视图、sps 等拆分为单独的块,因此所有客户表都在客户中。 架构,产品中的产品。 架构等,因此要从客户地址表中进行选择,我会从 customer.address 中执行 select *
不幸的是,Subsonic 忽略架构/所有者名称,只提供基表名称。 这很好,因为模式之间没有重复项(例如 Customer.Address 和 Supply.Address 并不同时存在),但我只是觉得如果可以按模式拆分,代码会更清晰。
理想情况下,我希望能够通过模式/所有者更改命名空间 - 我认为这对 SubSonic 的影响最小,但使生成的代码更易于阅读。
问题是,我已经爬遍了 Subsonic 源代码,但不知道如何做到这一点(我用 VB 编码而不是 C# 没有帮助 = 是的,我知道,归咎于 ZX Spectrum!
)之前解决过这个问题或者知道如何解决它,我将非常感激,
提前致谢。
埃德
I've just started using Subsonic 2.2 and so far very impressed - think it'll save me some serious coding time.
Before I dive into using it full time though there is something bugging me that I'd like to sort out.
In my current database (a SQL2008 db) I have split the tables, views, sps etc. up into separate chunks by schema/owner name, so all the customer tables are in the customer. schema, products in the product. schema etc., so a to select from the customers address table i'd do a select * from customer.address
Unfortunately, Subsonic ignores the schema/owner name and just gives me the base table name. This is fine as I've no duplicates between schemas (e.g Customer.Address and Supplier.Address don't both exist) but I just feel the code could be clearer if I could split by schema.
Ideally I'd like to be able to alter the namespace by schema/owner - I think this would have least impact on SubSonic yet make the resulting code easier to read.
Problem is, I've crawled all over the Subsonic source and don't have a clue how to do this (doesn't help that I code in VB not C# = yes I know, blame the ZX Spectrum!!)
If anyone has tackled this before or has an idea on how to solve it, I'd be really grateful,
Thanks in advance.
Ed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也打算建议采用多提供商方法。
但许多管道已经处于亚音速状态。
如果您在 CS_ClassTemplate.aspx 中编辑几行,您可以为每个所有者配置文件创建一个命名空间。 将第 58 行(我使用的是 v2.1)更改为
所有者所在的位置
您将其放在上面第 14 行附近。这样您就可以为每个所有者拥有一个命名空间,例如:
Northwind.供应商、Northwind.客户等
我将 dbo 保留为 Northwind,因此所有测试都无需进行大量编辑即可编译。
我运行了一个简单的选择查询,我认为它会按照您想要的方式工作。
I was going to suggest the multiple provider approach too.
But a lot of the plumbing is already in subsonic for ownership.
If you edit a couple of lines in CS_ClassTemplate.aspx you can create a namespace for each owner profile. Change around line 58 (I'm using v2.1) to
where owner is
You put that up above, around line 14. This way you can have a namespace for every owner like:
Northwind.Suppliers, Northwind.Customers, etc.
I left dbo as just Northwind so all the tests would compile without a lot of editing.
I ran a simple select query and I think it will work the way you want.
您也可以在 3.0 中使用我们的 t4 模板执行此操作(但仅限 3.5)。 这是一个非常好的反馈——我们也许应该默认构建它!
很高兴你在这里得到一些帮助。
You could do this in 3.0 as well using our t4 templates (but it's 3.5 only). This is a really good bit of feedback - we should build this in by default perhaps!
Glad you got some help here.
只是为了让你知道我现在可以工作了 - 或者至少可以编译! :-) 为了让所有者解决方案充分工作,您需要对类模板进行更多更改,否则表/键函数位于错误的命名空间中。
我还尝试过存储过程模板。 我无法(在短时间内)弄清楚如何为每个所有者拆分成单独的文件/命名空间,因此我在每个 sp 函数前面加上了所有者和下划线。
但是,万一您遇到同样的问题,您就会知道可以解决。
埃德
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
您可以尝试执行具有相同底层数据库连接的单独提供程序,如下所示:
我认为您不能以这种方式使用架构本身作为键,但您至少可以结合使用 includeTableList 和生成的命名空间。 您说不同模式之间没有重复的表名,因此它可能会起作用。
You could try doing separate providers that have the same underlying database connection, like so:
I don't think you can use the schema itself as a key in this way, but you could at least work around the issue with a combination of includeTableList and generatedNamespace. You said that you don't have duplicate table names across the different schemas, so it just might work.