Categories
Development

Subsonic 3 – ActiveRecord – T4 tweak

Quick reminder : I’m using Subsonic 3 ActiveRecord on a MSSQL database.

One of the nice things with Subsonic 3 is to be able to generate your classes from the database fast and easy.

But sometimes when you are many working on the same project or when you work on different machines, it happens that your database doesnt have exactly the same nameĀ  as the original and the T4 files provided will not generate the parameters for your stored procedure.

A quick fix is to edit the method GetSPParams in SQLServer.ttinclude

Replace this line :

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

With these

SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
string[] restrictions = new string[4] { connStringBuilder.InitialCatalog, null, spName, null };

And then simply run your .tt files again.

Download the zip file containing the modified SQLServer.ttinclude

If you have improvements that you have made, feel free to write about them in the comment section.