简体   繁体   English

IronPython的Azure表存储查询

[英]Azure Table Storage Query from IronPython

I've got a project that uses IronPython as a scripting engine to perform various tasks. 我有一个使用IronPython作为脚本引擎执行各种任务的项目。 One of those tasks needs to do some table lookup's on the Azure Table storage, however the table layouts are different, and will change often, so I need the model classes to be defined in Python. 这些任务之一需要在Azure Table存储上进行一些表查找,但是表布局是不同的,并且会经常更改,因此我需要在Python中定义模型类。

Here is the problem I'm running into, whenever I run a query it complains that a base class from my project is not supported by the client library. 这是我遇到的问题,每当我运行查询时,它都会抱怨客户端库不支持我项目中的基类。

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

Python Code: 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# Code: 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) { }
    }
}

Is there anything obvious that I'm missing? 有什么明显的我想念的东西吗? In my commented code, it seems to recognize my base class properties when I manually create it, however it does not when I try returning it from a query. 在我的注释代码中,当我手动创建基类属性时似乎可以识别它,但是当我尝试从查询中返回它时却无法识别。

The problem you are facing is related to System.Data.Services.Client which is used by Microsoft.WindowsAzure.StorageClient . 您面临的问题与Microsoft.WindowsAzure.StorageClient使用的System.Data.Services.Client有关。

It restricts which types can be used in the data services client. 它限制了可以在数据服务客户端中使用的类型。 This seems to prevent any implementation of IDynamicMetaObjectProvider (basically any dynamic object and therefore any object of an IronPython class) to be used during deserialization of your query result. 这似乎阻止了在查询结果反序列化期间使用IDynamicMetaObjectProvider的任何实现(基本上是任何动态对象,因此也就是IronPython类的任何对象)。

I tested the scenario using Azure Storage 1.7.0.0, 2.0.6.0 and 2.1.0.0-rc confirming your results. 我使用Azure Storage 1.7.0.0、2.0.6.0和2.1.0.0-rc测试了此方案,以确认您的结果。

You could always have a look at the source and see if another deserializer for AtomPub could be used. 您可以始终查看源代码,并查看是否可以为AtomPub使用另一个反序列化器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM