Closed tlogik closed 7 years ago
Hi Thomas,
Just my first observation, without going into detail, the example above should be:
var pq = client.Cypher
.MergeEntity(fbPage, "page")
.MergeEntity(fbPagePost, "post")
.MergeEntity(fbPagePost.Language, "language")
.MergeEntity(fbPagePost.Author, "author")
.MergeRelationship(new OwnedByRelationship("post", "page"))
.MergeRelationship(new HasLanguageRelationship("post", "language"))
.MergeRelationship(new WroteRelationship("author", "post", fbPagePost.CreatedAt));
if (fbPagePost.Category != null)
pq = pq.MergeEntity(fbPagePost.Category, "category")
.MergeRelationship(new WithCategoryRelationship("post", "category"));
if (fbPagePost.Author.Country != null)
pq = pq.MergeEntity(fbPagePost.Author.Country, "country")
.MergeRelationship(new OriginatesRelationship("author", "country"));
if (fbPagePost.AttachedLink != null)
pq - pq.MergeEntity(fbPagePost.AttachedLink, "link")
.MergeRelationship(new LinksToRelationsship("post", "link"));
pq.ExecuteWithoutResults();
The pq
isn't stateful, it returns a query object from each fluent statement, so to conditionally add to the query you need to keep returning the value, ie pq = pq.MergeRelationship
like string concatenation, instead you keep losing your changes to the query.
You will then be able to remove the additional executes.
I haven't gone into much detail as to what else is going on here, let me know if that helps you out.
cheers
Simon
Worked like a charm. Thanks for clarifying. Appreciate your responses highly. Kindly Thomas
This is going to a bit long because of the code examples since it is taken from my test application. Some parts are removed for readability.
Observe the code below
I am creating query
pq
. I have a couple of null checks and if the objects have value i add them to thepq
query by means ofpq.MergeEntity...
Problem is that the actual CQL created does not contain any entry about the null checked values, even thou they had value and thus the code was hit.It seems that the merging of country, link and category are not actually being added to the
pq
query.To make i work i had to do the following that then produces quite a lot more roundtrips to the db
now i create separate queries for each null check. This is not very efficient but it does however work.
And now the question. Is it possible to append to a query, essentially like in the first approach where i just add more
MergeEntity
statements to the same querypq
Thanks Thomas
extra Example CQL produced from the first code where country and link checks were hit becuase they had value.