我有一个项目,使用 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/