c# - 来自 IronPython 的 Azure 表存储查询

标签 c# azure ironpython azure-table-storage

我有一个项目,使用 IronPython 作为脚本引擎来执行各种任务。其中一项任务需要在 Azure 表存储上进行一些表查找,但是表布局不同,并且会经常更改,因此我需要在 Python 中定义模型类。

这是我遇到的问题,每当我运行查询时,它都会提示客户端库不支持我的项目中的基类。

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) { }
    }
}

有什么明显我遗漏的东西吗?在我的注释代码中,当我手动创建它时,它似乎可以识别我的基类属性,但是当我尝试从查询返回它时,它却不能识别。

最佳答案

您遇到的问题与 System.Data.Services.Client 有关。由 Microsoft.WindowsAzure.StorageClient 使用.

它限制数据服务客户端中可以使用哪些类型。这似乎阻止了 IDynamicMetaObjectProvider 的任何实现(基本上是任何动态对象,因此也是 IronPython 类的任何对象)在查询结果反序列化期间使用。

我使用 Azure 存储 1.7.0.0、2.0.6.0 和 2.1.0.0-rc 测试了该场景,以确认结果。

您可以随时查看the source看看是否有另一个解串器 AtomPub可以用。

关于c# - 来自 IronPython 的 Azure 表存储查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17658227/

相关文章:

c# - 我可以使用 .net 检查电子邮件地址是否存在吗?

iis - 由于 'Slow Requests' 限制,Azure 网站不断重新启动

azure - 保留子网范围内的私有(private)IP地址

c# - 如何插入带有 1 :n relationship in Azure App Service 的实体

ironpython - 如何将 IronPython 与 App.Config 一起使用?

.net - 从代码访问 Silverlight DataGrid 列标题中的控件

c# - 使用 2 个列表进行拖放 - 两个列表都激活相同的 OnDrop 事件

c# - 查找文本 block /文本的高度

c# - 如何在读取 CSV 记录时将空字符串转换为 null?

python - 强制进行浮点计算