C# Neo4jClient-不支持System.Linq.Expressions.ConstantExpression类型的表达式
无法在neo4jclient查询中创建对象并设置其布尔属性 我正在用neo4jclient做一个项目,到目前为止效果很好。但现在,当我尝试将查询中创建的对象的属性设置为true时,它会引发以下异常: 不支持System.Linq.Expressions.ConstantExpression类型的表达式 查询很简单:C# Neo4jClient-不支持System.Linq.Expressions.ConstantExpression类型的表达式,c#,.net,neo4j,neo4jclient,C#,.net,Neo4j,Neo4jclient,无法在neo4jclient查询中创建对象并设置其布尔属性 我正在用neo4jclient做一个项目,到目前为止效果很好。但现在,当我尝试将查询中创建的对象的属性设置为true时,它会引发以下异常: 不支持System.Linq.Expressions.ConstantExpression类型的表达式 查询很简单: return await _graphClient.Cypher.Match("(u1:User)-[:FOLLOW]->(u2:User)")
return await _graphClient.Cypher.Match("(u1:User)-[:FOLLOW]->(u2:User)")
.Where((UserModel u1) => u1.Id == userId)
.Return(u2 => new UserWithRelationsDto { User=u2.As<UserModel>(), IsFollow = true })
.Limit(usersToShow)
.ResultsAsync;
我尝试使用布尔变量和真值。但它抛出了一个不同的异常:
不支持表达式valueDAL.Repositories.Neo4jUsersRepository+c__DisplayClass5_1.isFollow
如果我去掉bool属性,查询就会工作。
可能是虫子?这附近有工作吗 解决方案:
return await _graphClient.Cypher.Match("(u1:User)-[r:FOLLOW]->(u2:User)")
.Where((UserModel u1) => u1.Id == userId)
.Return((u2,r) => new UserWithRelationsDto { User=u2.As<UserModel>(), IsFollow = r!=null})
.Limit(usersToShow)
.ResultsAsync;
很抱歉我错过了这个,还有另一种方法,那就是使用With语句:
var isFollow = false;
await _graphClient.Cypher
.Match("(u:User)")
.With($"{{IsFollow:{isFollow}, User:u}} AS u2")
.Return(u2 => u2.As<UserWithRelationsDto>())
.ResultsAsync;
或许最简单的就是:
await _graphClient.Cypher
.Match("(u:User)")
.With("{IsFollow:true, User:u} AS u2")
.Return(u2 => u2.As<UserWithRelationsDto>())
.ResultsAsync;
无论哪种方式-.With都允许您在Cypher中创建一个匿名类型,您可以将其直接解析到DTO中
await _graphClient.Cypher
.Match("(u:User)")
.With($"{{IsFollow:{true}, User:u}} AS u2")
.Return(u2 => u2.As<UserWithRelationsDto>())
.ResultsAsync;
await _graphClient.Cypher
.Match("(u:User)")
.With("{IsFollow:true, User:u} AS u2")
.Return(u2 => u2.As<UserWithRelationsDto>())
.ResultsAsync;