【问题标题】:How to truncate table using Telerik OpenAccess ORM?如何使用 Telerik OpenAccess ORM 截断表?
【发布时间】:2011-08-08 11:55:58
【问题描述】:

我试过了

ObjectScope.GetSqlQuery("TRUNCATE TABLE %table_name%", null, null).Execute();

ObjectScope.GetOqlQuery("TRUNCATE TABLE %ClassName%Extent").Execute();

第一行什么都不做。而第二次抛出异常:

line 1:10: unexpected token: ["TABLE",<42>,line=1,col=10]
Original Query: TRUNCATE TABLE DayExtent

【问题讨论】:

  • 您不应该提供表名而不是变量吗?
  • 当然,在实际代码中我提供表名。我使用 %table_name% 作为占位符。

标签: .net telerik openaccess telerik-open-access


【解决方案1】:

ExecuteDDLScript 方法在 DDL 和 DML 脚本之间没有区别。它只要求没有开放的对象范围。

        IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
        //do something here
        scope.Dispose();
        string tableToTruncate = "SOME_TABLE";
        scope.Database.GetSchemaHandler().ExecuteDDLScript(string.Format("TRUNCATE TABLE {0}", tableToTruncate));
        scope = ObjectScopeProvider1.GetNewObjectScope();
        //do something again

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多