2011-08-08 39 views
1

我試圖如何使用Telerik OpenAccess ORM截斷表格?

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 
+0

不應該提供表名而不是變量嗎? –

+0

當然,在真實的代碼中我提供了表名。我已經使用%table_name%作爲佔位符。 – Enlightened

回答

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 

希望有所幫助。