我有一个项目,它使用 IronPython 作为脚本引擎来执行各种任务。其中一项任务需要在 Azure 表存储上进行一些表查找,但是表布局不同,并且会经常更改,因此我需要在 Python 中定义模型类。
这是我遇到的问题,每当我运行查询时,它都会抱怨客户端库不支持我的项目中的基类。
Unhandled Exception: System.InvalidOperationException: The type 'IronPython.NewTypes.IPTest.BaseModelClass_1$1' is not supported by the client library.
蟒蛇代码:
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) { }
}
}
有什么明显的我失踪了吗?在我注释的代码中,当我手动创建它时,它似乎可以识别我的基类属性,但是当我尝试从查询中返回它时它不会。