I’m using Neo4j Release 2 with Java SE 7. I’ve reviewed the online C# client examples and still have not been able to accomplish this simple task. Below is my code snippet that most closely follows syntax from examples post here: (https://github.com/Readify/Neo4jClient/wiki/cypher-examples).
My problem is that the query always come back with a count of zero.
In this example, I am trying to test if the node Person with a Name property equal to “Beth” has already been created as a node in my database. In this case I know the node exists as I can query for Beth using Cypher via Neo4j's web browser client.
The var query always come back with a count of zero elements. Why?
string myname = "Beth";
var query = client.Cypher
.Match("(person:Person)")
.Where((Person person) => person.Name == myname)
.Return(person => person.As<Person>())
.Results;
Console.WriteLine(query.Count()); // returns 0
There has to be something slightly different between the two queries you are using.
Follow the debugging instructions at https://github.com/Readify/Neo4jClient/wiki/cypher#debugging to diagnose the difference and then react accordingly.
There is not enough information in your question for me to give you a better answer, especially as you haven't said what query you are using in the web console.
Also, if you're only just transitioning into C# for the first time with Neo4j, then remember that property names are case sensitive. If you created your node in the web console with a name property, you'll never find it using Name in your C# definition.
Related
If i execute this part of the code:
var adressenDetailses = new KlippsTestEntities().AdressenDetails.Count();
the variable adressenDetailses has the value 961. (That means the enumeration has values)
If I want to check the values of the IEnumerable AdressenDetails during debugging then Visual Studio says
'For the functionevalution all threads have to be executed'.
I execute the Thread by clicking the reload icon. Now Visual Studio says:
'The expression can not be evaluated. The process is not supported.
Unknown error: 0x80070057.'
Does anyone knows the answer to how I can fix the problem?
Entity Framework is lazy.
I mean this is a good way. It will only fetch the data it needs to fetch up-front. Any linking values - like links/FKs to other tables - will get only when it is asked.
This is why you are are seeing this behavior when you are debugging, but if you wrote the full code out and ran it normally it would produce the correct values.
You can enable "eager loading" using an Include line
var adressenDetailses = new KlippsTestEntities()
.Include(x => x.AdressenDetails) //tells EF to eager load that link
.Select(x=> x.AdressenDetails); //"I would only like to see data on the details"
var addressCount = adressenDetailses.Count();
Now you should be able to debug the first line and see the specific details of that object.
Side note: you don't need to add the .Select(x=> x.AdressenDetails); clause.
In ADO.Net I created a DAL file that took parameters from the user and if they were not null, the query got extended based on if statements. Now I want to do the same in Entity Framework.
I have searched a number of sites including Stack Overflow but failed to get my satisfactory answer.
for Reference, the following link also could not help me
Select Query with Where condition depending on list values in asp.net
the required scenario is
cmd.text = "SELECT FROM tbl_name WHERE id>0 "
if(param_value != null)
{
cmd.text += " AND (param_name = '#param_value')";
if(!cmd.contains("param_name"))
cmd.parameters.addwithvalue("param_name", #param_value);
cmd.parameters["param_name"] = #param_value;
}
// proceed further with cmd.text
please ignore the syntax right now, I just wanted to convey my concept of what I want to do.
I want to apply the same concept for Entity Framework
Well two days back I found a scenerio in wheich the query (text) was built in an aspx.cs file and it was passed as it is to a custom built function in DAL which passed the text to cmd.text and processed the rest of retrieval in an ADO.net style.
This method is potentially dangerious as anyone with a bit knowlege can break this security down to grounds.
I want to create a query that has parameters as well as its vales like I have shown in above code block.
Using LINQ-to-SQL:
var param_value = 0;
db.tbl_name.Where(x => x.id > 0).Where(x => x.some_property == param_value).ToString();
If you look at the generated SQL, you'll see that's its parameterized (it picks the param_names, though).
I added the ToString() at the end, just so you could see the resulting SQL; based on OP, I'd say to leave this off, and keep modifying the query further directly in LINQ, rather than converting to SQL as a string and concatenating.
I just found out working with Entity framework is a totally different world that classic approach. In here, we work with models/objects and their relationships with each other and we access them based on that relationship. So to answer the question we need to get that model first like
Movie movie = db.Movies.Find(id);
and than from that, we get a model object which does have different properties in it like title, IMDb, rating etc.
We get them repeatedly using where clause as below:
db.Where(movies=>movies.IMDb==10).Where(movies=>movies.title=="The Game Plan")
this all is equal to the following in classic approach
AND (IMDb = 10) AND (title = 'The Game Plan')
following that, one can extend his query as much as he likes.
Again ignore the syntax here because I am here t convey the idea only.
For reference, the following links might be helpful keeping in mind the context i have explained.
Multiple where conditions in EF - StackOverflow
Im using Neo4JClient To populate the Nodes in a Neo4JDB.
I have a Function that is invoked to create Nodes and Label them as well.
The First Parameter is the Label, and the Second Parameter is the node attribute
function CreateConcpet( String sLabelString, String sDataSpaceName)
{
var newConcept = new Concept {DataSpace=sDataSpaceName};
client.Cypher
.Create("(concept:{labelstring} {ParamnewConcept})")
.WithParam("ParamnewConcept",newConcept)
.WithParam("labelstring",sLabelString)
.ExecuteWithoutResults();
}
This uses the Parameter to Substitute for the Label.
This does not work. From the various posts, I understand that WithParam does not work for Labels.
If the dreaded ExecuteCypher is the only way, can someone help me with a code snippet, that executes a string as query. I cannot find a code snippet, while the documentation gives the call, Im unable to find a sample which creates the query object and executes the String Query.
You can't parametize things that will affect the compiled query plan. Labels are used in the query plan, thus, no parameters.
This is a general restriction with how parameters work in Neo4j, not just Neo4jClient.
I had the very same problem which was (after much mashing of teeth) easily solved ...
I had two types of nodes, Person and Union. These two lines labeled them
MATCH (n) where n.surname >' ' SET n :Person
MATCH (n) where n.surname is null SET n :Union
This was dependent on the two node types having different metadata which distinguished them.
I am updating node property through C# using following code, but this code will not update node property. If i run only query part in neo4j browser then it work. Is any another approach to solve this issue?
//Code
CypherQuery query = new CypherQuery("
MATCH (n { Name: \"Person B1\" })
SET n.Name = \"Person B2\"
RETURN n",
new Dictionary<string, object>(), CypherResultMode.Projection);
Then probably your match fails.
Does the code actually return the node in question?
You should also use parameters for your data, both for the existing and new ´Name` properties.
And Person would most probably be a label.
This isn't at all a supported way of using Neo4jClient. Please try consulting any of the documentation.
Then, the documentation also includes debugging guidance to help you determine what is different between your C# vs. the Cypher you expect.
I am using Nucleon Database Master, which so far has been great for managing my mongodb servers. However, there are a few examples where they show the LINQ Query editor in use with your own data types and classes, but I can't find any documentation anywhere on how to do it.
There are hints in the comments in the c# query it generates:
//Linq to MongoDB Help:http://www.mongodb.org/display/DOCS/CSharp+Driver+LINQ+Tutorial
//The following sample shows a LINQ to MongoDB query. Use #FileInclude command to add your entity class for LINQ Query.
//var collection = this.db.GetCollection<Employee>("Employees");
//var result = from emp in collection.AsQueryable<Employee>()
//where emp.FirstName == "Andrew"
//select emp;
//Output(result);
Everything in the editor works great, apart from I have no idea how to "Use #FileInclude command to add your entity class LINQ Query".
I'm sure it's possible as they have screenshots demonstrating it on their website (I have emailed them, but haven't got a response).
http://www.nucleonsoftware.com/images/dm/LinqToEF_Select1.png
So, anyone either know how to do this, or otherwise have an idea what the #FileInclude thing might be about?
Have had a response back from Nucleon Software, and thought I'd share it here for anyone else with the same question:
You need to add a comment at the top of the query editor, e.g.:
//#FileInclude C:\myFile.cs
using System;
using System;
using System.Collections.Generic;
....
However, they apparently will soon be adding a feature to add you custom DLL's to the LINQ query.