Subsonic 3.0.0.3 不生成存储过程的参数
我有一个带有一堆存储过程的 SQL Server 2008 数据库。当我使用 Subsonic 3.0.0.3 提供的 ActiveRecord 模板时,它会为我的所有存储过程生成方法,但它们没有任何参数。我是服务器上的 dbo,可以在 Management studio 中执行存储过程,没有任何问题。
示例存储过程
CREATE PROCEDURE [dbo].[prc_Sample]
@FileName VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF EXISTS ( SELECT * FROM Sample WHERE FileName = @FileName )
BEGIN
RETURN -1
END
RETURN 0
END
示例生成方法
public StoredProcedure prc_Sample(){
StoredProcedure sp=new StoredProcedure("prc_Sample",this.Provider);
return sp;
}
如果我检查 SQLServer.ttinclude,我可以看到用于获取存储过程的所有方法都在那里,但由于某种原因它们没有生成。这不是存储过程名称中包含下划线的问题 - 无论有没有下划线,都会出现问题。
有什么想法或有人知道如何调试模板文件吗?
I have a SQL Server 2008 database with a bunch of stored procedures. When I use the ActiveRecord Template provided with Subsonic 3.0.0.3, it generates methods for all of my stored procedures, but they do not have any parameters. I am dbo on the server and can execute the stored procedures with no issue from Management studio.
Example Stored Procedure
CREATE PROCEDURE [dbo].[prc_Sample]
@FileName VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF EXISTS ( SELECT * FROM Sample WHERE FileName = @FileName )
BEGIN
RETURN -1
END
RETURN 0
END
Sample Generated Method
public StoredProcedure prc_Sample(){
StoredProcedure sp=new StoredProcedure("prc_Sample",this.Provider);
return sp;
}
If I check SQLServer.ttinclude, I can see that all of methods for getting stored procedures are there, but for some reason they are not generating. And this isn't an an issue of having underscores in the stored procedure names - this is broken with and without underscores.
Any ideas or anyone know how to debug a template file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,我必须调整
SQLServer.ttinclude
才能使其正常工作。在该文件中找到GetSPParams()
方法并更改一行:从
到
。
BlackMael 的答案有一个有用的链接,帮助我弄清楚如何调试和单步执行模板代码。
现在我还不能100%确定我的改变是好的(可能会有一些不利影响)。我只是还没有机会彻底测试它,需要阅读更多有关
Restrictions
的内容,因为它们与GetSchema()
方法有关。但现在,这解决了我的问题,我可以成功传递我的存储过程参数。更新:这可能与我的数据库文件嵌入在App_Data中的VS解决方案中有关。也许使用独立的 SQL Server 实例开箱即用效果更好。
I had the same issue, and I had to tweak the
SQLServer.ttinclude
to get it working. Inside that file find theGetSPParams()
method and change one line:from
to
.
BlackMael's answer has a helpful link that helped me figure out how to debug and step through the template code.
Now I'm not 100% sure yet that my change is a good one (there may be some adverse effects). I just haven't had a chance to test it thoroughly and need to read up some more on
Restrictions
as they pertain to theGetSchema()
method. But for now, that solved my problem and I can successfully pass in my stored proc parameter.Update: This may have something to do with the fact that my DB file is embedded in the VS solutin in App_Data. Perhaps this works better out of the box with a stand-alone SQL Server instance.
调试 T4 模板文件...
T4 教程:调试代码生成文件
使用 SubSonic-30-Templates 中指向 SqlExpress 中 Northwind 实例的项目,我添加了上面的存储过程。重新生成 StoredProcedures.tt 并愉快地创建了它......
虽然我使用最新和最好的版本,但我没有注意到参数丢失的问题。
您可以发布您的 Settings.ttinclude 和可能的 SqlServer.ttinclude 文件吗?或者也许是他们的链接? StoredProcedures.tt 也可能不错。
To debug a T4 template file...
T4 Tutorial: Debugging Code Generation Files
Using the project in the SubSonic-30-Templates that points to an instance of Northwind in SqlExpress I added the stored procedure above. Re-generated the StoredProcedures.tt and it happily created...
Though I use the latest and greatest build, I've not noticed issues with parameters missing.
Can you post your Settings.ttinclude and possibly SqlServer.ttinclude file? Or maybe a link to them? The StoredProcedures.tt may be good too.
另一个可能的原因是数据库没有分配 dbo。
Another possible cause of this is that the Database has no dbo assigned.
与 Kon M 的回答类似,我将 SQLServer.tt 中的行更改为:
这解决了我的问题。
Similar to Kon M's answer I changed the line in SQLServer.tt to:
This resolved the problem for me.