views:

209

answers:

3

I'm evaluating SubSonic 3.0 for use in our business as a replacement for our POCO objects. I'm new to SubSonic, literally installing it yesterday. I've gotten to the point where I can connect to one database using the 3.0 LINQ T4 Templates, and have been wooed by the promise of being able to connect to multiple databases in one application using SubSonic.

My issue is I can't find any documentation on how to use the T4 Templates with multiple databases (e.g. adding another connection string, setting up the Settings.ttinclude etc).

I've searched Google and Stackoverflow for an answer to see how this would be done or if its even possible. Any help would be appreciated.

A: 

So I seemed to be able to make it work by adding another connectionString to the web.config, and then adding a 2nd set of templates for that connectionString, it works, but it doesn't seem 'clean' or even really that DRY to me.

It also seems that I could do almost the same thing with the .NET Built in LINQ by adding multiple .dbml files.

Can anyone give me some reasoning at this point why we shouldn't just use the built in LINQ support over a 3rd party ORM like SubSonic?

Scott Lance
By "built in LINQ support" are you referring to Linq-To-Sql or Entity-Framework or something else? Each ORM has a different feature set and you should pick the ORM whose feature set matches your needs best (which is admittedly not easy). Your new question here should really be a separate question from your first, but then it would likely be a duplicate of others.
Michael Maddox
I am referring to L2SQL. To be honest in my research I've been coming across the same difficulty in every ORM, but I still have NHibrinate to look at.
Scott Lance
+1  A: 

(In reply to your answer of your question)

Can anyone give me some reasoning at this point why I shouldn't just use the built in LINQ over a 3rd party ORM like SubSonic?

On immediate thought: SubSonic supports more than just Microsoft Sql Server.

bob
As we are a Microsoft shop, 100% of our database interaction happens through Microsoft SQL Server. I appreciate that SubSonic supports multiple RDBMS, and in the future there may be a situation where we will need to have that support, but at the current time this is not a concern.
Scott Lance
+5  A: 

Cross posting from the subsonic mailing list:

Oh yeah I do this all the time, the trick is two copies of the templates(easy) or editing the templates to iterate over two sets of tables(harder). In the second settings.tt change the name of the connection string to reflect the other database. You might also want to change the namespace so that you don't have conflicts where table names are the same. It seems hacky but I don't think it is because it allows you to make changes to the templates for each database independently.

If you really want only one set of templates the easiest way to go about it is to edit SQLServer.tt (or your choice of database) and override how LoadTables works such that it will accept a list of connections rather than a single one. I have to say this is a pain and it is going to be much harder than having 2 copies of the files.

stimms
Hi there, I'm very new to this and I don't understand what do you want to say by this "settings.tt change the name of the connection string to reflect the other database" How could I do that? I've created the 2 sets of t4 templates in different folders and configured them, but I still don't get it to work, it doesn't recognize all the stored procedures I've got in the first database loaded. In fact, it recognizes the stored procedures I've got, but not its parameters. Thank you
vikitor
Good solution, using a separate set of templates for each DB. this has helped me a great deal, thanks. The only issue I had was with tables with the same name in both DBs. I got around this by overriding the name in the CleanUp() method in the settings.ttinclude file (just below the Excluded table array).
fat_tony