Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm the author of Neo4jClient. (The guy who gives his software away for free.)</p> <p>Q1a:</p> <blockquote> <p>"Can I use the CRUD API to look up node A by its ID, create node B from a POCO, create a relationship between A and B"</p> </blockquote> <p>Cypher is the way of not just the future, but also the 'now'.</p> <p>Start with the Cypher (lots of resources for that):</p> <pre><code>START user=node:user(Id: 1234) CREATE user-[:INVITED]-&gt;(user2 { Id: 4567, Name: "Jim" }) Return user2 </code></pre> <p>Then convert it to C#:</p> <pre><code>graphClient.Cypher .Start(new { user = Node.ByIndexLookup("User", "Id", userId) }) .Create("user-[:INVITED]-&gt;(user2 {newUser})") .WithParam("newUser", new User { Id = 4567, Name = "Jim" }) .Return(user2 =&gt; user2.Node&lt;User&gt;()) .Results; </code></pre> <p>There are lots more similar examples here: <a href="https://github.com/Readify/Neo4jClient/wiki/cypher-examples" rel="nofollow">https://github.com/Readify/Neo4jClient/wiki/cypher-examples</a></p> <p>Q1b:</p> <blockquote> <p>" and add B's ID to a legacy index in one request?"</p> </blockquote> <p>No, legacy indexes are not supported in Cypher. If you really want to keep using them, then you should stick with the CRUD API. That's ok: if you want to use legacy indexes, use the legacy API.</p> <p>Q2.</p> <blockquote> <p>"If not, what is the alternative? Is the CRUD API considered legacy code and should we move towards a Cypher-based Neo4j 2.0 approach?"</p> </blockquote> <p>That's exactly what you want to do. Cypher, with labels and automated indexes:</p> <pre><code>// One time op to create the index // Yes, this syntax is a bit clunky in C# for now graphClient.Cypher .Create("INDEX ON :User(Id)") .ExecuteWithoutResults(); // Find an existing user, create a new one, relate them, // and index them, all in a single HTTP call graphClient.Cypher .Match("(user:User)") .Where((User user) =&gt; user.Id == userId) .Create("user-[:INVITED]-&gt;(user2 {newUser})") .WithParam("newUser", new User { Id = 4567, Name = "Jim" }) .ExecuteWithoutResults(); </code></pre> <p>More examples here: <a href="https://github.com/Readify/Neo4jClient/wiki/cypher-examples" rel="nofollow">https://github.com/Readify/Neo4jClient/wiki/cypher-examples</a></p> <p>Q3.</p> <blockquote> <p>"Does this Cypher-based approach mean that we lose POCO-to-node translation for create operations? That was very convenient."</p> </blockquote> <p>Correct. But that's what we collectively all want to do, where Neo4j is going, and where Neo4jClient is going too.</p> <p>Think about SQL for a second (something that I assume you are familiar with). Do you run a query to find the internal identifier of a node, including its file offset on disk, then use this internal identifier in a second query to manipulate it? No. You run a single query that does all that in one hit.</p> <p>Now, a common use case for why people like passing around <code>Node&lt;T&gt;</code> or <code>NodeReference</code> instances is to reduce repetition in queries. This is a legitimate concern, however because the fluent queries in .NET are immutable, we can just construct a base query:</p> <pre><code>public ICypherFluentQuery FindUserById(long userId) { return graphClient.Cypher .Match("(user:User)") .Where((User user) =&gt; user.Id == userId); // Nothing has been executed here: we've just built a query object } </code></pre> <p>Then use it like so:</p> <pre><code>public void DeleteUser(long userId) { FindUserById(userId) .Delete("user") .ExecuteWithoutResults(); } </code></pre> <p>Or, add even more Cypher logic to delete all the relationships too:</p> <p>Then use it like so:</p> <pre><code>public void DeleteUser(long userId) { FindUserById(userId) .Match("user-[:?rel]-()") .Delete("rel, user") .ExecuteWithoutResults(); } </code></pre> <p>This way, you can effectively reuse references, but without ever having to pull them back across the wire in the first place.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload