亚音速 从 msdb 中选择
我想使用 Subsonic 执行以下查询:
SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory]
虽然聚合部分对我来说很容易,但问题在于表的名称。我应该如何强制 Subsonic 从不同于默认数据库的数据库中进行选择。
更多详细信息:
这是我在程序中执行此操作的方式:
SqlQuery query = new Select(Aggregate.Max(@"restore_date",@"restore_date")).From(@"msdb.dbo.restorehistory");
return query.ExecuteScalar<DateTime>();
以及我得到的异常:
Need to have at least one From table specified
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过吗:
使用它总是一个好主意
如果出现问题, 。
queryString 将是一个参数化的 Sql 语句。
编辑:
你真的不应该在 SubSonic 中使用字符串。
您可以使用
从 DAL 获取字符串。
否则,在从数据库中重命名/删除列并重新创建 SubSonic DAL 后,您将不会出现编译时错误。
Edit2:
我刚刚读到您想要查询另一个数据库中的表,而不是用于生成 DAL 的数据库。
我以前从未这样做过,但我想这不起作用的原因是因为 subsonics 的 SqlQuery 类尝试从指定的表名查询模式(以便能够获取限定名称等,失败并吞下异常(或者只是忽略该表)。在构建查询字符串时,您的表不会被包含在内,因为它从未添加到 FromTables 集合中,
但是有一个快速的解决方案应该有效:
或者如果您经常需要访问其他数据库,您 可以这样做。甚至可以创建另一个提供程序并在一个项目中使用两个 DAL。
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.