I wrote this cypher query in C#:
var myClint = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "1412");
myClint.Connect();
var getName= myClint.Cypher.Match("(n:Person)
.Return(n => n.As<Person>())
.Results;
I have setters and getters in Person class to get the name, ssn, and age for everyone in the Person node. I want to display those information on a grid view. I did that with sql server but I do not know how to do it with neo4j.
Thanks in advance
In essence, you need to create your own DataTable
, you can do it manually with code like this:
public static DataTable ConvertToTable(IEnumerable<Person> people)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Age");
foreach (var person in people)
{
var row = dt.NewRow();
row[0] = person.Name;
row[1] = person.Age;
dt.Rows.Add(row);
}
return dt;
}
But that means you have to write one of those for each type, so you can do this instead:
public static DataTable ConvertToTableAutomatic<T>(IEnumerable<T> items)
{
DataTable dt = new DataTable();
var properties = typeof(T).GetProperties();
foreach (var property in properties)
dt.Columns.Add(property.Name);
foreach (var item in items)
dt.Rows.Add(FillRow<T>(dt.NewRow(), item, properties));
return dt;
}
private static DataRow FillRow<T>(DataRow row, T item, PropertyInfo[] properties)
{
foreach (var property in properties)
row[property.Name] = property.GetValue(item);
return row;
}
But bear in mind - you won't be able to update the Neo4j
DB with this, just display the information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.