我有这个功能基于customerId
和entityModel
进行查询。我想让它适用于所有不同的模型。换句话说,我想将CustomerFeatureEntity
类作为参数传递给此函数:
public TableQuery<CustomerFeatureEntity> StorageQuery(string customerId)
{
TableQuery<CustomerFeatureEntity> query = new TableQuery<CustomerFeatureEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, customerId));
}
如果我确保从TableEntity
类继承参数,那也很好。是否有可能在C#中完成其中一项?
答案 0 :(得分:1)
是的,您只需要重新定义它以使用具有where约束的泛型。
public TableQuery<T> StorageQuery<T>(string customerId) where T : TableEntity
{
TableQuery<T> query = new TableQuery<T>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey",
QueryComparisons.Equal, customerId));
}