问题描述
我正在尝试为Azure表创建通用实现。问题是当我使用ExecuteQuery函数时,它总是向我返回以下错误:
我确实可以运行Execute函数来执行TableOperation的删除,更新,创建,检索等操作
这是我在项目中创建的类:
基类
public abstract class TableEntityBase : TableEntity
{
private string TableName { get; set; }
public TableEntityBase(string tableName)
{
TableName = tableName;
}
public string GetTableName() => TableName;
}
然后显示其界面
public interface ITableEntityBase<T> where T : TableEntityBase
{
TableResult InsertOrMerge(T entity);
TableResult Delete(T id);
IEnumerable<T> GetByExpression(string query);
IEnumerable<T> GetAll();
}
还有我所拥有的表的类
public class Mapping : TableEntityBase
{
public Mapping() :
base(EntityLogicalName)
{
}
private const string EntityLogicalName = "Mapping";
public string Source { get; set; }
}
public interface IMapping : ITableEntityBase<Mapping>
{
}
至少我的服务班
public class TableEntityBaseServices<T> : ITableEntityBase<T> where T : TableEntityBase,new()
{
protected CloudTable _cloudTable;
protected string tableName = ((T)Activator.CreateInstance(typeof(T))).GetTableName();
public TableEntityBaseServices()
{
IConfiguration appSettings = AppSettings.GetAppSettings().GetSection("ConnectionStrings");
_cloudTable = CloudStorageAccountExtensions.CreateCloudTableClient(CloudStorageAccount.Parse(appSettings.GetSection("AzureConfig").Value)).GetTableReference(tableName);
_cloudTable.CreateIfNotExistsAsync();
}
//...Other methods that work well
IEnumerable<T> ITableEntityBase<T>.GetByExpression(string query)
{
return _cloudTable.ExecuteQuery<T>(new TableQuery<T>().Where(query)); //Error here: Unable to evaluate the expression. Operation not supported.
}
}
然后,映射服务为:
public class MappingServices : TableEntityBaseServices<Mapping>,IMapping { }
static async Task Main(string[] args)
{
var serviceProvider = new ServiceCollection()
.AddSingleton<IMapping,MappingServices>()
.BuildServiceProvider();
IMapping _mappingService = serviceProvider.GetrequiredService<IMapping>();
try
{
IEnumerable<Mapping> mappings = _mappingService.GetByExpression(TableQuery.GenerateFilterCondition("PartitionKey",QueryComparisons.Equal,"test1"));
}
catch (Exception e)
{
throw e;
}
}
我看到了一个问题this answer,但是就我而言,我不知道该做什么,因为我已经在服务类中定义了new()
。我在哪里搞砸了?
预先感谢:)