我使用Azure并发现性能很慢.为了减少往返时间,我将以下查询分成一个查询.
var queryItem = _graphClient
.Cypher
.Start(new
{
n = Node.ByIndexLookup("item_idx", "SKU", sSKU1),
})
.Return<Node<Item>>("n");
Run Code Online (Sandbox Code Playgroud)
代码中的其他地方我有以下语句
var queryItem = _graphClient
.Cypher
.Start(new
{
m = Node.ByIndexLookup("item_idx", "SKU", sSKU2),
})
.Return<Node<Item>>("m");
Run Code Online (Sandbox Code Playgroud)
我试图将上面两个查询组合成一个像这样的查询
var queryItem = _graphClient
.Cypher
.Start(new
{
n = Node.ByIndexLookup("item_idx", "SKU", sSKU1),
m = Node.ByIndexLookup("item_idx", "SKU", sSKU2),
})
.Return<Node<Item>>("n");
Run Code Online (Sandbox Code Playgroud)
我知道上面仅针对单列,所以我尝试使用以下return语句
.Return((n, m) => new
{
N = n.CollectAs<Node<Item>>(),
M = m.CollectAs<Node<Item>>()
});
Run Code Online (Sandbox Code Playgroud)
但是我对以下声明有疑问
Node<Item> item1 = itemQueryResult.First();
Run Code Online (Sandbox Code Playgroud)
它说错误不能隐式地将类型'AnonymousType#1'转换为'Neo4jClient.Node.
你能建议一个简单的语法或返回多列以及提取第一个节点的方法吗?TIA.
使用 CollectAs<> 时使用显式转换来解决错误中的问题
来自 WebMethod 的代码
return client.Cypher
.Match("(person:Person)")
.Where((Person person) => person.Email == username)
.OptionalMatch("(person)-[:SPEAKS]-(language:Language)")
.OptionalMatch("(person)-[:CURRENT_LOCATION]-(country:Country)"
.Return((person, language, country) => new ProfileObject
{
Person = person.As<Person>(),
Language = language.CollectAs<Language>(),
Country = country.CollectAs<Country>()
}).Results.ToList();
Run Code Online (Sandbox Code Playgroud)
来自国家级的代码:
public class Language
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
ProfileObject 类的新代码:
public class ProfileObject
{
public Person Person { get; set; }
public IEnumerable<Node<Language>> Language { get; set; }
public IEnumerable<Node<Country>> Country { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
仅当我将 ProfileObject 设置为返回 IEnumerable> …
I am trying to create unique constrain using accepted answer found at: Neo4jClient - Create index from within Neo4jClient?
I am using Neo4jClient v1.1.0.11
The example is:
graphClient.Cypher
.CreateUniqueConstraint("identity", "property")
.ExecuteWithoutResults();
Run Code Online (Sandbox Code Playgroud)
The problem is that when I execute this example I receive this exception:
SyntaxException: Invalid input ')': expected an identifier character, whitespace or NodeLabel (line 1, column 31 (offset: 30)) "CREATE CONSTRAINT ON (identity) ASSERT property IS UNIQUE" ^
When I use this statement:
client.Cypher
.Create("CREATE CONSTRAINT ON (c:User)ASSERT …Run Code Online (Sandbox Code Playgroud) 我在将以下 Cypher 查询转换为 Neo4jClient 语法时遇到问题。
MATCH n WHERE NOT (HAS (n.User)) 或 n.User = "username" RETURN n
这是我目前所拥有的,添加了一些关系逻辑并省略了 HAS 逻辑
var results = Client.Cypher
.OptionalMatch("(result)-[connection:Connection]-(result2)")
.Where((Result result) => result.User == username)
.Return((result, connection, result2) => new Neo4jResultSingle()
{
SearchedNode = result.As<Node<Result>>(),
RelationshipConnection = connection.As<RelationshipInstance<Connection>>(),
Relationship = connection.As<RelationshipInstance<ConnectionRelationship>>(),
RelationshipedNode = result2.As<Node<Result>>()
}).Results.ToList();
Run Code Online (Sandbox Code Playgroud) 我无法从Cypher查询中检索匹配的关系.
我有这个简单的试用代码:
var movie = client.Create(new Movie { Title = "The Matrix" });
client.Create(new Actor { Name = "Keanu Reeves" },
new ActedIn(movie, new ActedInPayload { Role = "Neo" }));
client.Create(new Actor { Name = "Hugo Weaving" },
new ActedIn(movie, new ActedInPayload { Role = "Agent Smith" }));
var actorsAndRoles = client
.Cypher
.Start(new { movie = movie })
.Match("actor-[r:ACTED_IN]->movie")
.Return((actor, r) => new
{
Actor = actor.As<Node<Actor>>()
// ActedIn = r.As<?????>()
})
.Results;
Run Code Online (Sandbox Code Playgroud)
问题是我无法弄清楚如何施放r(具有匹配的关系).
尝试了各种".As"类型演员,但都没有奏效.转换为关系不起作用,因为我的关系类没有无参数构造函数 - 但是基本类本身没有无参数构造函数,所以不要认为这会起作用.另一方面,转换为RelationshipReference会导致异常.根本不投射(只返回r)会导致"不支持"的异常.
有关此问题的一些相关SO条目,但建议的代码不再有效或已弃用.
如何检索匹配的关系?
我正在尝试执行以下操作(这在neo4J cypher上很容易.
merge (ee:Person { id: "id1234" })
Run Code Online (Sandbox Code Playgroud)
如何确保下一个创建不会在c#Neo4Jclient中创建另一个节点????
迫切需要这个
client.Cypher.Merge("(user:User {Id: {Id} })")
.onCreate()
.set("user= {newUser}")
.withParams(new { ... } )
.executeWithoutResults();
Run Code Online (Sandbox Code Playgroud)
似乎Merge没有被提升.知道为什么吗?因为即使对象完全相同,它仍然会创建一个新节点.
谢谢,R
在使用Neo4j时,我能够创建带有标签的节点数组,然后在这些节点之间创建关系.标签基本上是我的POCO的映射(Dog标签与C#中的Dog POCO有关),这些POCO是从一个只包含ID属性的简单基础POCO实现的.
当我知道要检索的节点的类型/标签时,我能够使用node.As <T>语法在return语句中转换它.但是,当执行诸如遍历节点之间的路径之类的操作时,我将不知道我正在遍历的节点的类型.虽然在技术上可以将节点转换为我的POCO实现的基本类型,但是我会丢失特定于超类的所有属性.
关于如何开始使用这个的任何想法?

我通过运行以下方法尝试获取结果集时收到错误/异常:
public IEnumerable<NeoProduct> GetAllProductsUnderCategory(int categoryId)
{
var query = neo.Cypher.Match("(c:Category{CategoryId:{id}})<-[*](p:Product)")
.WithParam("id", categoryId)
.Return(p => p.As<NeoProduct>()).Results;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它是一个返回NeoProducts列表的非常简单的方法.NeoProduct是一个简单的POCO,具有以下属性:
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public int ParentCategoryId { get; set; }
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪是:
[OverflowException: Value was either too large or too small for an Int64.]
System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt) +14278344
System.String.System.IConvertible.ToInt64(IFormatProvider provider) +55
System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +14285879
Neo4jClient.Serialization.CommonDeserializerMethods.CoerceValue(DeserializationContext context, PropertyInfo propertyInfo, JToken value, IEnumerable`1 typeMappings, Int32 nestingLevel) in D:\temp\tmpC806\Neo4jClient\Serialization\CommonDeserializerMethods.cs:101 …Run Code Online (Sandbox Code Playgroud) 这是一个两部分问题
我尝试创建一个新节点时收到此错误
无法将类型'Neo4jClient.NodeReference'隐式转换为'Neo4jClient.GraphClient'
我这里有3个类第一个连接到GraphDB服务器并返回客户端变量以供以后在其他类中使用
public GraphClient GetConnection()
{
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
return client;
}
Run Code Online (Sandbox Code Playgroud)
然后是New_Node类,看起来像这样
class New_Node
{
public GraphClient Node { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后是Graph Operations类,它具有CreateNode方法
public GraphClient CreateNode()
{
Graph_Connection connection = new Graph_Connection();
var NewNode = connection.GetConnection();
var Created_Node = NewNode.Create(new New_Node());
return Created_Node;
}
Run Code Online (Sandbox Code Playgroud)
如何在另一行代码上设置Node的属性而不是用节点创建它们,我想让我的应用程序更具动态性,这种方式似乎很难编码
var refA = client.Create(new Person(){Name ="Person A"});
在Java中,人们可以做到这一点
Node user1 = this.graphDb.createNode();
user1.setProperty("name", "Mike");
Run Code Online (Sandbox Code Playgroud) 我有一个执行Cypher查询的方法,我希望返回所有节点及其与查询中指定节点(64)有关系的名称:
start n = node(64) match (n)--(x) return x.Name;
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试在我的代码中执行此操作时,它不想工作.这是我的方法:
public string GetAllFirstLevelRelatives(long NodeId)
{
string QueryResult = null;
try
{
var query = client_connection
.Cypher
.Start(NodeId, client_connection.RootNode)
.Match(NodeId, "--(x)")
.Return<Node<GraphNode>>("(x).name");
QueryResult = query.Results.ToString();
}
catch (Exception e)
{
}
return QueryResult;
}
Run Code Online (Sandbox Code Playgroud)
我想这个查询返回名称.
有人可以帮帮我吗?
我有一个连接到 Neo4j 数据库的 MVC Asp.Net 应用程序。在我的数据库中,实体(m:Movie)<-[r:HAS_WATCHED_MOVIE]-(u:User)之间存在关系。movieuser
我想要做的是按降序返回一个IEnumerable<Movie>包含前 3 部电影(顶级电影是HAS_WATCHED_MOVIE关系最多的电影)。
我已经想出了一个 Cypher 查询来做到这一点,它是这样的:
MATCH (m:Movie)<-[r:HAS_WATCHED_MOVIE]-(b)
RETURN m, COUNT(r)
ORDER BY COUNT(r) DESC
LIMIT 3
Run Code Online (Sandbox Code Playgroud)
由于我是 Neo4j C# 客户端的新手,我不确定如何在 C# 中编写此查询?