C# oData筛选器不适用于MongoDB和Web API的导航属性

C# oData筛选器不适用于MongoDB和Web API的导航属性,c#,mongodb,odata,mongodb-csharp-2.0,asp.net-web-api-odata,C#,Mongodb,Odata,Mongodb Csharp 2.0,Asp.net Web Api Odata,控制器看起来像 public class NodesRestController : ODataController { private INodeService _nodeService; public NodesRestController(INodeService nodeService) { _nodeService = nodeService; } [EnableQuery()] public IQueryable

控制器看起来像

    public class NodesRestController : ODataController
{
    private INodeService _nodeService;
    public NodesRestController(INodeService nodeService)
    {
        _nodeService = nodeService;
    }
    [EnableQuery()]
    public IQueryable<Node> Get()
    {
        return _nodeService.GetAllNodes();
    }
    [EnableQuery()]
    public Node Get(string id)
    {
        return _nodeService.GetNodeById(id);
    }
}
{
"_id" : "5688d5b1d5ae371c60ffd8ef",
"Name" : "RTR1",
"IP" : "1.2.2.22",
"NodeGroup" : {
    "_id" : "5688d5aad5ae371c60ffd8ee",
    "Name" : "Group One",
    "Username" : null,
    "Password" : null
}}
Id是使用ObjectId.GenerateNewId().ToString()生成的,因此它们存储为字符串

节点和节点组是纯POCO

public partial class NodeGroup : EntityBase
{
    public string Name { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string LoginPrompt { get; set; }
    public string PasswordPrompt { get; set; }
    public string ReadyPrompt { get; set; }
    public string Description { get; set; }
}
 public partial class Node : EntityBase
{
    public string Name { get; set; }
    public string IP { get; set; }
    public virtual NodeGroup NodeGroup { get; set; }
}
public abstract class EntityBase 
{
    //[JsonIgnore]
    // [BsonRepresentation(BsonType.ObjectId)]
    // [BsonId]
    public string Id { get; set; }
}
问题

小田乌里斯样

http://localhost:9910/api/NodesRest
http://localhost:9910/api/NodesRest?$expand=NodeGroup
http://localhost:9910/api/NodesRest?$expand=NodeGroup&$filter=Name eq 'RTR1'
很好

但当我尝试在导航属性上进行筛选时

http://localhost:9910/api/NodesRest?$expand=NodeGroup&$filter=NodeGroup/Name eq 'Group One'
这给了我一个例外

消息:“无法确定表达式的序列化信息:ConditionalExpression。”,

我使用了_collection.FindAll();它成功了


当我在内存收集中使用而不使用mongoDB时,它对我很有用。还有


mongodb的c#驱动程序中的AsQueryable方法有些问题

您的上一个示例URI不包括
$expand
选项。我使用了expand相同的结果。您更新的URI使用Microsoft.AspNet.OData 5.7.0版(最新稳定版本)生成正确的筛选结果。您使用的是什么版本?我应该指出,在我的测试中,我使用了一个带有屏蔽数据的假节点服务。我没有使用MongoDB。当我在内存收集中使用MongoDB而不使用MongoDB时,它对我很有效。mongodb的c#驱动程序中的AsQueryable方法有些问题。不管怎样,请检查我的答案以确定答案。
http://localhost:9910/api/NodesRest?$expand=NodeGroup&$filter=NodeGroup/Name eq 'Group One'