How to disable auto increment Identifier (id) of the neo4j? - neo4j

I'm working with two relational and non relational banks. I need the relational IDs to be attributes for nodes in the non relational database, but Neo4j does not allow the generation of these attributes.

You can't disable the internal Neo4j id, that's necessary for Neo4j to run properly.
What you can do is introduce your own id field (id is a valid property you could use, as the internal neo4j id does not use the id field) and add an index (or unique constraint, if needed).

Related

Neo4j OGM updation deletes other attributes of entity

I am using neo4j OGM for CRUD operations. But when I use session.save(entity, 0) where entity has only id and updated attribute, other attributes associated with entity are deleted fro neo4j entity.
For example Object car has id, name and year.
If I just set id and year in entity, name attribute will be deleted, which i donot want.
I donot want to fetch and update.
To preserve existing values in the database, you have to load first the data.
This is the way all OGM / ORM work.
To update just specific attributes you can use a dedicated cypher query.

Create unique relationship based on relationship attribute

Just like we can create a unique constraint on a "Node" attribute, can i create a unique constraint on a "Relationship" attribute. In my system every relationship has a unique "name" attribute, i want to enforce it in neo4j.
Thank you
Utpal
Sorry, there is no support for unique constraints on relationships in neo4j 3.0.x, and nothing in the 3.1 beta documentation. Relationships can have existence constraints (for neo4j enterprise), but no unique constraints.
The best you can do is ensure you're always using MERGE when creating your relationships and that the name attribute is present for that MERGE.

Is it a good practice to use an "id" attribute in Neo4J?

In my system I have a relational DB table with "id" columns, and I am representing some of that same data in Neo4J.
My first approach is to make an "id" attribute in Neo which correlates to the id column.
Is there any reason that this isn't a good practice? Does it conflict technically or conceptually with the node IDs that Neo generates?
If the ids serve the purpose of uniquely distinguishing the nodes that will get generated then yes its good to have one.
But keep in mind the possibility that if your graph grows in future and say a situation arrives that another DB table needs to be modelled into graph and by any chance say some ids in the new DB table conflict with the old DB table then in that situation you will get into trouble maintaining uniqueness of node.
And node ids that neo4j generates are recommended not to be used as they are prone to be reused in case the nodes are deleted.
In case you just want to model the DB table into graph database and dont want to relate the graph data to your db table later on, you can use UUID.randomUUID().toString() to generate random unique UUIDs(extremely less probability of duplicate UUID) for ids of nodes.

Entity Framework 4.1 Code First - How to map a string containing csv of Entity ID's (foreign keys) to the corresponding Entity

Before I submit my question, please be aware that I'm working with an existing database owned by a third party vendor, so unfortunately changing the database format is not an option.
Here's the issue: I have an Entity mapped to a database table that has a varchar column that contains one to many foreign keys in csv format. Those foreign keys correspond to the ID's of another Entity type. What I've been doing is writing a function that creates a List of ID's from that csv list and then I search for that Entity through the DBContect object. What I'd like to do is map a relationship between the entities. Is there a way to do that? Thanks!
Unfortunately there is no way to do that without changes in the database. EF is ORM tool but it is still very dependent on correctness of database design. Storing multiple values in single column is breaking even first database normal form. For EF your column containing csv data is single string value and you cannot make relation on that value.
Btw. it is even more complicated because the column cannot represent one-to-many relation in standard relational meaning - that would require dependent entities to contain Id of your master entity, not that master entity contains Ids of all dependent entities.

How should I handle maintaining row Identity for new records in Linq / Entity Framework?

What is the proper way to create a new unique shared key when using Linq and EF with SQL?
I could use a GUID upon inserting the record but I only want want my keys to have 7 digits or characters in it as they will appear in the URL of my MVC application. If this isn't an option, or it's just better with GUID's let me know.
If you do not need a unique key across machine boundaries then I would just go with a bigint/idenity that auto-increments by 1 (which is the default). You do not have to specify the identity when adding a new entity with EF, it will be auto-assigned. Once it has been assigned you can then use it as a FK.
In my opinion GUIDs are only useful in this context if you have to guarantee that the key is unique across multiple databases, i.e. you create they key on one machine (A) and want to transfer the data to another machine (B), retaining the key. This is not possible with bigint keys since machine B might have inserted other data with the same key already.

Resources