Subsonic 3.0.0.3 不生成存储过程的参数

发布于 2024-08-03 20:09:27 字数 825 浏览 3 评论 0原文

我有一个带有一堆存储过程的 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 技术交流群。

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

发布评论

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

评论(4

电影里的梦 2024-08-10 20:09:27

我遇到了同样的问题,我必须调整 SQLServer.ttinclude 才能使其正常工作。在该文件中找到 GetSPParams() 方法并更改一行:

string[] restrictions = new string[4] { DatabaseName, null, spName, null };

string[] restrictions = new string[3] { null, null, spName };

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 the GetSPParams() method and change one line:

from

string[] restrictions = new string[4] { DatabaseName, null, spName, null };

to

string[] restrictions = new string[3] { null, null, spName };

.

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 the GetSchema() 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.

二智少女猫性小仙女 2024-08-10 20:09:27

调试 T4 模板文件...

T4 教程:调试代码生成文件

使用 SubSonic-30-Templates 中指向 SqlExpress 中 Northwind 实例的项目,我添加了上面的存储过程。重新生成 StoredProcedures.tt 并愉快地创建了它......

public StoredProcedure prc_Sample(string FileName){
    StoredProcedure sp=new StoredProcedure("prc_Sample",this.Provider);
    sp.Command.AddParameter("FileName",FileName,DbType.AnsiString);
    return sp;
}

虽然我使用最新和最好的版本,但我没有注意到参数丢失的问题。

您可以发布您的 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...

public StoredProcedure prc_Sample(string FileName){
    StoredProcedure sp=new StoredProcedure("prc_Sample",this.Provider);
    sp.Command.AddParameter("FileName",FileName,DbType.AnsiString);
    return sp;
}

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.

握住我的手 2024-08-10 20:09:27

另一个可能的原因是数据库没有分配 dbo。

Another possible cause of this is that the Database has no dbo assigned.

昔日梦未散 2024-08-10 20:09:27

与 Kon M 的回答类似,我将 SQLServer.tt 中的行更改为:

string[] restrictions = new string[4] { null, null, spName, null };

这解决了我的问题。

Similar to Kon M's answer I changed the line in SQLServer.tt to:

string[] restrictions = new string[4] { null, null, spName, null };

This resolved the problem for me.

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