Reputation: 7447
I have this function doing queries based on a customerId
and entityModel
. I want to make it generic for all different models. In other words, I want to pass CustomerFeatureEntity
class as a parameter into this function:
public TableQuery<CustomerFeatureEntity> StorageQuery(string customerId)
{
TableQuery<CustomerFeatureEntity> query = new TableQuery<CustomerFeatureEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, customerId));
}
Also it would be nice if I make sure that parameter inheritance from TableEntity
class. Is either one of those possible to be done in C#?
Upvotes: 0
Views: 33
Reputation: 33815
Yes, you'd just need to redefine it to use generics with a where constraint.
public TableQuery<T> StorageQuery<T>(string customerId) where T : TableEntity
{
TableQuery<T> query = new TableQuery<T>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey",
QueryComparisons.Equal, customerId));
}
Upvotes: 1