Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:35:59+00:00 2026-05-15T02:35:59+00:00

I want to execute the following query using Subsonic: SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory] While

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:36:00+00:00Added an answer on May 15, 2026 at 2:36 am

    Have you tried:

    DateTime result = new Select(Aggregate.Max(@"restore_date",@"restore_date"))
           .From<RestoreHistory>()
           .ExecuteScalar<DateTime>();
    

    Also it’s always a good idea to use

    SqlQuery query = new Select(...),
    String queryString = query.BuildSqlStatement();
    

    if something goes wrong.
    queryString will be a parametrised Sql statement.

    Edit:

    And your really shouldn’t use strings with SubSonic.
    You can use

    RestoreHistory.Columns.RestoreDate  // = restore_date
    RestoreHistory.RestoreDateColumn.QualifiedName
    // = [msdb].[dbo].[restorehistory].[restore_date] (not sure about this one, just try it out)
    
    And
    
    RestoreHistory.Schema.TableName     // = RestoreHistory
    RestoreHistory.Schema.QualifiedName // = [msdb].[dbo].[restorehistory]
    

    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:

    DateTime result = new SubSonic.InlineQuery()
         .ExecuteScalar<DateTime>(
           "SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory]"
          );
    

    Or if your often need to access the other DB, you could even create another provider and work with two DALs’ in one project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute python code from C# with following code. static void Main(string[]
I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users
I'm trying to execute a query in PostgreSQL using the following code. It's written
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,
The following query uses join operation, i want the same query to execute without
I want the following code to execute when the myString is having either of
I want to execute a code helloword.cpp which takes in some argument from console
I want to execute one mysql statement where I have a select that is
I'm using freebase python to access the freebase api. I have the following query
I have this query: select top(2) property_id_ref ,image_file ,property_name from property_master a inner join

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.