0

I am getting this exception while creating nodes in NEO4J 2.0.3 using C# Client for NEO4J. My Node Structure is like this

namespace UserGraph.BusinessObjects
{
    public class UserInfo
    {
        public int UserID { get; set; }
        public string UserName { get; set; }
        public int HeadendId { get; set; }
        public int Score { get; set; }
        public string ThirdPartyObjID { get; set; }
        public long ThirdPartyTypeId { get; set; }
        public string[] ThirdPartyFriendsIds { get; set; }
        public List<Programme> Programs { get; set; }
        public List<Channel> Channels { get; set; }
    }

    public class Channel
    {
        public long ChannelID { get; set; }
        public String ChannelName { get; set; }
    }

    public class Programme
    {
        public long ProgrammeID { get; set; }
        public String ProgrammeName { get; set; }
    }
}

I think Neo4j nodes don't hold Complex data. I searched and found on this link http://docs.neo4j.org/chunked/stable/graphdb-neo4j-properties.html Can any one tell me is there any way by which i can store the list of channel and program objects in my UserInfo class.

Surjit Jana
  • 53
  • 1
  • 10
  • 1
    As the exception says you can only store an array of primitive types. It seems to me that you would be better off adding a relationship between the different node types. – stephenmuss Jul 10 '14 at 06:35
  • Thanks @stephenmuss for quick reply. It means i should create separate nodes for UserInfo, Channel and Programme. Once created I should create relationship between them. – Surjit Jana Jul 10 '14 at 06:47
  • that's right. That's a much more natural fit for a graph database. – stephenmuss Jul 10 '14 at 06:49
  • I fully agree with @stephenmuss, however just so you know, if you did want to store these elements, you'd basically need to use a custom serializer - you might find you need to for things like Dictionaries see http://stackoverflow.com/questions/23132187/can-neo4j-store-a-dictionary-in-a-node/23246331#23246331 for an example – Charlotte Skardon Jul 10 '14 at 12:48

1 Answers1

2

I am running into the same issue and I am not sure I agree with the concept that all complex "properties" should be relationships. At the end of the day, the entire "node" should be something that can be serialized and stored -- this is one of the advantages of using JSON to serialize/deserialize the node. Coder the following

public class Address {
    public string Line1 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Country { get; set; }
}

public class User {
    public string Name { get; set; }
    public string email { get; set; }
    public Address HomeAddress { get; set; }
    public Address WorkAddress { get; set; }
}

While create nodes for Addresses can be done, I would ask the question -- why should the developer be forced to create nodes and relationships for something like this. If I never intend to do any direct queries on the properties of the Address class independently of the main user, then it is far simpler to treat the entire user as a complex object and store it in its entirety as the data for the node in the graph.

Shawn
  • 115
  • 2
  • 13