Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question. Set custom label om MergeEntity #23

Open
tlogik opened this issue Feb 5, 2017 · 3 comments
Open

Question. Set custom label om MergeEntity #23

tlogik opened this issue Feb 5, 2017 · 3 comments

Comments

@tlogik
Copy link

tlogik commented Feb 5, 2017

Hi.
Is it possible to specify the label and/or labels to use when using the MergeEntity method?

Right now it just gets the typename of the class as label but i would like to decorate with other Neo labels as well.
Is that possible somehow?

example

 foreach (var subject in fbPagePost.Subjects)
                            {
                                var cq = client.Cypher
                                    .MergeEntity(fbPagePost, "fbpost")
                                    .MergeEntity(subject, "subject", labels: new []{"label1", "label2", "label3"})
                                    .MergeRelationship(new RelatesToRelationship("fbpost", "subject"));
                                cq.ExecuteWithoutResults();
                            }

Cheers
Thomas

@simonpinn
Copy link
Owner

Hi Thomas,

The only way you can set the label to be used is either with the CypherLabelAttribute or the fluent config With<Entity>("label")
You are able to set the labels to "label1,label2" and they will just be passed down to to CQL statement.

It isn't possible to change this at query time. Remember you can always use more than one class to represent a node, so you can always do it by adding a class for the purpose.

I'd also question why you would need to dynamically add a label, use them carefully, you should rarely need to use multiples, at least in my experience.

cheers

Simon

@tlogik
Copy link
Author

tlogik commented Feb 6, 2017

Hi Simon
The case.
I have many subjects each representing a different kind.
Right now i model using a Subject class.

  public class Subject
    {
        public string Kind { get; set; }
        public string Value { get; set; }
    }

It would be more relevant to be able to store these subject nodes with the Kind as label and then the Value as the only property of the Node.
Then it would be simpler to extract nodes by label.

This label would have to be set on query time.

Is it a design choice of the lib not to support querytime labels?

Cheers
Thomas

@simonpinn
Copy link
Owner

Hi Thomas,

If they're known "Kinds" then I'd consider modelling each as a separate class with a base class:

public abstract class Subject
        {
            public abstract string Kind { get; }
            public string Value { get; set; }
        }

        public class SomeSubject : Subject
        {
            public override string Kind => "SomeKind";
        }

There has been a discussion about respecting class hierarchy when setting the label, but I've never had the need.

Feel free to raise a PR if it's something you'd like to see 😄

cheers

Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants