I want to execute the following query using Subsonic:
SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory]
While the aggregate part is easy for me, the problem is with the name of the table. How should I force Subsonic to select from different database than default one.
More details:
This is the way I do it in my procedure:
SqlQuery query = new Select(Aggregate.Max(@"restore_date",@"restore_date")).From(@"msdb.dbo.restorehistory");
return query.ExecuteScalar<DateTime>();
And the exception I get:
Need to have at least one From table specified
Have you tried:
Also it’s always a good idea to use
if something goes wrong.
queryString will be a parametrised Sql statement.
Edit:
And your really shouldn’t use strings with SubSonic.
You can use
to get the strings from the DAL.
Otherwise you won’t get compiletime errors after renaming / deleting a column from your DB and recreating the SubSonic DAL.
Edit2:
I just read that you want to query a table that is in another database than the one you used for generating your DAL.
I have never done that before, but I guess the reason why this won’t work is because subsonics’ SqlQuery class tries to query the schema from your specified tablename (to be able to get the qualified name etc., fails and swallows the exception (or just ignories the table). While building the querystring, your table is not included because it was never added to the FromTables collection.
But there is a quick solution that should work:
Or if your often need to access the other DB, you could even create another provider and work with two DALs’ in one project.