2013-07-15 68 views
2

我有一個使用IronPython作爲腳本引擎執行各種任務的項目。其中一個任務需要在Azure Table存儲上進行一些表查找,但表格佈局不同,並且會經常更改,所以我需要在Python中定義模型類。來自IronPython的Azure Table存儲查詢

這是我遇到的問題,每當我運行一個查詢,它抱怨我的項目中的基類不被客戶端庫支持。

Unhandled Exception: System.InvalidOperationException: The type 'IronPython.NewTypes.IPTest.BaseModelClass_1$1' is not supported by the client library. 

Python代碼:

import clr 
import System 
clr.AddReference("System.Core") 
clr.ImportExtensions(System.Linq) 


class MyTable(AzureTableService.BaseModelClass): 
    def __new__(self, partitionKey, rowKey): 
     self.PartitionKey = partitionKey 
     self.RowKey = rowKey 
     return super.__new__(self) 

    MyTableDetails = ""; 

#I can manually create an entity, and it recognizes the base class, but not when I try to return from a query 
#working = MyTable("10", "10040") 
#print working.PartitionKey 

y = AzureTableService.GetAzureTableQuery[MyTable]("MyTable") 
z = y.Where(lambda c: c.PartitionKey == "10" and c.RowKey == "10040") 

print(z.Single()) 

C#代碼:

public class AzureTableService { 
    private CloudStorageAccount mStorageAccount; 
    public AzureTableService() { 
     CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => { 
      var connectionString = ConfigurationManager.AppSettings[configName]; 
      configSetter(connectionString); 
     }); 
     mStorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");   
    } 

    private TableServiceContext AzureTableServiceContext { 
     get { 
      var context = mStorageAccount.CreateCloudTableClient().GetDataServiceContext(); 
      context.IgnoreResourceNotFoundException = true; 
      return context; 
     } 
    } 
    public IQueryable<T> GetAzureTableQuery<T>(string TableName) { 
     return AzureTableServiceContext.CreateQuery<T>(TableName); 
    } 

    public class BaseModelClass : TableServiceEntity { 
     public BaseModelClass(string partitionKey, string rowKey) : base(partitionKey, rowKey) { } 
     public BaseModelClass() : base(Guid.NewGuid().ToString(), String.Empty) { } 
    } 
} 

有什麼明顯的是我失蹤?在我評論的代碼中,當我手動創建它時,它似乎識別我的基類屬性,但是當我嘗試從查詢中返回它時,它不會。

回答

0

您所面臨的問題與Microsoft.WindowsAzure.StorageClient使用的System.Data.Services.Client有關。

它限制哪些類型可用於數據服務客戶端。這似乎阻止了在查詢結果反序列化過程中使用IDynamicMetaObjectProvider(基本上任何動態對象,因此IronPython類的任何對象)的任何實現。

我使用Azure存儲1.7.0.0,2.0.6.0和2.1.0.0-rc測試了方案,以確認您的結果。

你總是可以看看the source,看看是否可以使用另一個解串器AtomPub