带有 MongoDb 的 C# 使用带参数类型变量的 Filter.OfType

时间:2021-03-16 16:25:00

标签: c# mongodb

以下代码给了我以下错误:mutationType 是一个变量,但像类型一样使用。
如何使用 Filter.OfType 和类型参数搜索具体类?

// BaseMutation is an abstract class. mutationType will contain a type of a concrete class.
public IEnumerable<BaseMutation> FindMutations(Type mutationType)
{

     var filter = Builders<BaseMutation>.Filter.OfType<mutationType>(); 
     ...            
}

我也试过typeof(BaseMutation).MakeGenericType(mutationType);

0 个答案:

没有答案
相关问题