2013-07-15 51 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