Defining Schema for Neo4J Using Neo4JClient in C# - c#

How to correctly/standardly define schema for neo4j database in my C# application?
In my application, I have nodes with properties and relations with properties. I want to define templates/Classes of these nodes and relations that can then be created and related at run time and retrieved as objects of a class with queries.
After a lot of search and research, I found something that was nearly related to my question:
http://blog.micic.ch/net/using-neo4j-graph-db-with-c-net
But according to the Neo4j Documentation these are legacy methods.
https://github.com/Readify/Neo4jClient/wiki
So What is the Current standard way in Neo4J 2.0? As we also have labels now.
I hope I am clear enough in my question. If not, Please let me know.

The basic idea is that now you use the Cypher querying capabilities to do everything, so where as Darko uses the REST API to Create / CreateRelationship the client has moved to use Cypher instead.
This means you no-longer need the Relationship based classes, and can stick to POCO (Plain Old CLR Objects) for storing and querying - which makes your code simpler to use...
The standard ways can all be found on the 'Cypher Examples' page on the Neo4jClient wiki, and I've put a gist up with an updated version of Darko's code.
All the addition of labels etc comes from the way you write the Cypher, and as Neo4jClient is as near as can be to being direct Cypher (but with C# niceness added in) the translation should be pretty simple.

Related

Fast in-memory graph database

Does anyone know of a good solution out there that can deal with processing a graph of interconnected nodes? For our purpose the nodes are locations and we move material with various attributes between these locations. At some point a user may need to query what material is at a particular location, where it came from etc. What I need to do is walk the graph/tree and sum up quantities along the way depending on what a user requests.
I was thinking an in-memory graph database or alternatively a graph library may be suitable for this kind of problem but I am not 100% sure. It needs to be called from c# 4.5.
I read about Microsoft's Trinity and there is also Neo4j but I haven had any experience with any of them.
There are at least two in-memory c# alternatives:
Fallen-8 - http://www.fallen-8.com/
OrigoDB - https://origodb.com/ The author just mentioned in a mailing list that he was working on a graph example.
We're using VelocityGraph for our graph needs - http://www.velocitygraph.com/
But VelocityGraph not an in-memory solution, so I'm not sure how it suits your requirements.
Memgraph is an in-memory graph database, and it has support for C#.

Is there any way of treating database records as objects

I come from an Objective-C programming background and as such, am used to using Core Data for storing my data. Core data allows you to define fields (attributes) which you can then refer to as if they were objects in code, for each item in the database.
I wondered if there is a similar way of doing things for C#.
A bit more background
I have a treeview on my winform. The treeview allows people to add and remove new nodes. I've created a subclass of TreeNode so I can store a little more information against each node but I'd like to have all of the database transactions for adding / deleting done as part of this subclass. For instance, when I delete a node from the tree that has subnodes, I can easily remove this from the tree by calling Remove (knowing it will remove all subnodes too), but I also need the database to keep those changes too.
So, as above - is there a way to treat DB records as objects?
Hope that's clear enough!
Entity Framework, LLBLGEN, NHibernate to name a few ORMs
I would suggest looking at Beginner's Guide to ADO.NET Entity Framework
EntityFramework (Nuget Package) (Nuget is the preferred way to install packages such as EF)
Also, take a look at Sam Saffron's How I learned to stop worrying and write my own ORM and Small is Beautiful - .NET Micro ORMs

How to use a local database in c#?

I've made a local database for a C# project:
I know basic SQL commands, but haven't worked with databases in C#.
What I'd like to know specifically is:
How to read from the database (query)
How to add and update rows
The database only consists of 3 tables, so I don't think anything fancy is needed.
First, you should learn a bit about various technologies and APIs for connecting with a database.
The more traditional method is ADO.NET, which allows you to define connections and execute SQL queries or stored procedures very easily. I recommend digging up a basic tutorial on ADO.NET using Google, which may differ depending on what type of project you're creating (web app, console, WinForms, etc).
Now days, ORMs are becoming increasingly popular. They allow you to define your object model in code (such as every database table would be a class, and columns would be properties on that class) and bind to an existing database. To add a new row to a table, you'd just create an instance of a class and call a "Save" method when you're done.
The .NET framework has LINQ to SQL and the Entity Framework for this sort of pattern, both of which have plenty of tutorials online. An open source project I really like is Castle Active Record, which is built on top of NHibernate. It makes defining ORMs quite easy.
If you have specific questions about any of the above, don't hesitate to post a new question with more specific inquiries. Good luck!
Update:
I thought I'd also put in one last reference as it seems you might be interested in working with local database stores rather than building a client/server app. SQLite allows you to interact with local stores on the file system through SQL code. There's also a .NET binding maintained by the SQLite guys (which would in theory allow you to work with the other platforms I mentioned): http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
You can use SQLCE.
This blog will give you a good start.
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
Here is a small tutorial that should be helpful to you.
You can make use of the SqlDataReader to read data
and the SqlCommand to Insert Update Delete rows from your tables.
http://www.dotnetperls.com/sqlclient
You could use it by adding following to your Startup.cs
services.AddDbContext<DemoDbContext>(options => options.UseSqlite("Filename=data.db"));

How do I verify that my LINQ-to-SQL model matches the database schema?

I am absolutely new to the .NET world, and started with C# on friday. I have some experience with database apps, though.
We will go with LINQ-to-SQL for a medium scale project. I am used to generating my schema from classes and keep track of changes with subversion and equivalents to Ruby's Migrations. There obviously is no easy way to do this with LINQ itself.
So I thought of generating the schema (and do some data access) with Castle Project's ActiveRecord and use Migrator.NET Tarantino or dbdeploy.net for the schema updates. (Any suggestions for this?)
My main question is: How do I verify that my LINQ classes still match the database schema? Does LINQ throw exceptions if the schema does not match? Can I iterate over all the LINQ classes and invoke some verify method?
I already found that sqlmetal is the way to regenerate the classes.
PS: We will use SQL Server (2008 or 2005).
This tool will help sync them, but I'm unsure if it'll show differences...may be of some use though. (:
EDIT: As KristoferA said in his comment, it does support comparisons (: - thanks KristoferA.
As for the:
I am used to generating my schema
from classes and keep track of changes
I just added a DDL generation feature to Huagati DBML/EDMX Tools (ver 1.47, released today). It can generate DDL diff scripts in case you have added things to your Linq-to-SQL designer but not yet added them to the database.

C# and MySQL - Gentle Framework alternatives

I'm playing around at the start of a personal project in C# and MySQL.
I am familiar with the use of the Gentle Framework (using MyGeneration to generate the classes, based on the data model). Here's what I like about Gentle;
Simple-to-use [class].Retrieve(id) / [object].Persist() semantics with strong-typing of fields;
I start with the DB data model, and choose when to generate new code files;
MyGeneration allows for some 'manual code sections' which are kept across generations...
...and partial classes allow me to add permanent code in parallel files, e.g. simple read-only properties (like 'FullName' from FirstName and Surname members for a Person object) - or I could use inheritance;
I find it a tolerable and quick way to create a DAL, and add certain Business-Object-Layer-like facilities to it.
Unfortunately, to query efficiently, I end up using queries / SqlCommands a fair bit, and relies on weakly typed references to column names etc., and appears to risk sidestepping the object broker and therefore caching advantages. In any event, Gentle is no longer being developed, and it seems like a good time to consider alternatives.
So, what should I consider?
Generation of strongly-typed ADO Datasets is possible, but it seems like it will be difficult to add to it (e.g. that 'FullName' virtual column) in a way that will persist after updates to the table structure with regeneration of the dataset.
NHibernate seems to have lots of fans... but my first looks into it seem to suggest that the XML data definition is king, not the existing data-model in the DB. It also looks quite heavy on dependencies;
The SubSonic demo appears to suggest it generates files, and in the demo of WebAppProjects, looks like it might generate files in a way that I could add to, or inherit from;
The MySql Connector.Net tools appear not to support the dataset generation for Linq (e.g. via drag-and-drop), and I suspect that this is a key need for strongly-typed data access.
Your thoughts will be gratefully appreciated! Thank you in advance...
I had some experience with Gentle and I do have to admit that it was pretty inefficient with queries. I would suggest looking into NHibernate, since it has a rich community. It is true that XML definitions are preferred, but there are ways of doing the mappings using class-level attributes.
SubSonic (especially the 3.0 version) looks very promising with its use of T4 templates. That should give you more control over code generation. It can do LINQ too.
Don't invest in LINQ-to-SQL, since the rumors are that is going to be discontinued.
Assuming that the .Net 3.5 Framework is an option for being used, then you can take a look at Microsoft's Entity Framework (released with .Net 3.5 Service Pack 1).
The Entity Framework allows the generation of DAL classes based on your database schema, but the maintenance of these classes are hidden behind an XML file that can quickly and easily be updated to account for schema changes by a simple command from the Visual Studio IDE.
I am working on a project where we use the Entity Framework with MySQL with few problems.
The main disadvantage to this option is that the official .Net connector provided by MySQL does not yet support the Entity Framework - there is a paid alternative known as MyDirect.Net
link textI would go for Subsonic, mature DAL generator and improves productivity by great margin.
We have used it with both MySQL and SQL Server - no headaches. Generates classes for Tables, Stored procedures, column names. So every time we find ourselves doing Somthing Dot Intellisense Move Arrow keys and semicolon.
Any time your schema changes, you can regenerate those classes and you are home. Also, you can extend them by creating partial classes.
It supports almost all of the SQL Semantics - Joins, loading Collection by primary key, adding WHERE clause, Order by, Count, Top, Calling stored procedures, views and so on and Intuitive syntax is big plus.
To give you some glimpse- For Books table[BookID-PK, title, AuthorID], It generates several types of methods.
Insert method which takes Title, AuthorID
Nullable columns are optional
parameters a.k.a C# Nullable type ?
Update method wich takes BookID, AuthorID, Title
Load Book by Primary key (Useful when displaying detail page)
BookCollection and Book Entities, Just call BookCollection.Load and you have list of books ready to bind to any databound control
Here's quick link.
Thanks,
Maulik Modi
Thanks to both Filip and Snorkpete for your suggestions - your comments and links proved helpful.
I will probably try SubSonic first; it looks like something I will understand and be able to get going with quickly (today should answer that), and I was surprised to see that it is indirectly supported by MS as they employ the guy who writes it. T4 also looks very interesting.
The Entity Relationship Model also looks interesting, and the link to MyDirect may be helpful in the future. The only down side here is one of expectation; MS have screwed-up their approach in the past by making them easy to create the initial design with drag-and-drop, then much harder later to modify or keep up-to-date.
Anyway, thank you both again, and I'll try to keep this question updated.
Nij
I use a bit of SQL to generate strongly typed objects out of tables, it's based on one built by Cade Bryant, but I've made some tweaks. The code it generates is not 100% compilable but it saves a lot of boiler plate work and the gaps are easy to fill (i would make all the properties fully fledged properties if i were you, or bear the wrath of jon skeet!)
http://NotifyURL.com/sql

Categories

Resources