views:

58

answers:

2

I encountered bug in my programm because of SubSonic3 returns records with default connection string in

SingleOrDefault(ByVal expression As System.Linq.Expressions.Expression(Of System.Func(Of Company.filter, Boolean)), ByVal connectionString As String, ByVal providerName As String)

In Subsonic sources, Database.cs line 323:

instance = Activator.CreateInstance<T>();

I think that was the cause of problem in my case. It creates instance with default constructor and then returns it as a result, that's where we loose custom connection string.

Personally I fixed it with adding 2 lines to ActiveRecord.tt template, in SingleOrDefault function, which has connectionString argument:

            single._db=new <#=Namespace#>.<#=DatabaseName#>DB(connectionString, providerName);
            single._repo = new SubSonicRepository<<#=tbl.ClassName#>>(single._db);

But I think you should examine this problem deeper, Rob :)

A: 

I don't follow. You specify the name of the ConnectionString is Settings.tt - that's the one we use.

Rob Conery
Yes, but it's default connection string. And SingleOrDefault function called with custom ConnectionString parameter returns record, that point to the wrong database.For example, I have several databases, which has identical structure, but they used separately. Lets say I have Company1 and Company2 databases. If I use record.SingleOrDefault(x => x.name="joe", GetConnectionStringForCompany2, ProviderName) it will return me record object that is pointing to the Company1 database, but I passed connection string for Company2 database. I hope that illustrates the situation.
Nickname
A: 

So, do you have any news?

Nickname