I try to create a cypher-query in my Java-Spring-Application which should answer the question "give all employees who did not create a item in item.nameList":
#Query("START it=node:__types__(className = 'de.my.domain.ItemCl') MATCH empl-[r:CREATE]->it WHERE (it.name NOT IN ({0})) RETURN DISTINCT empl")
List<Employee> findAllEmployeesWhoNeverCreatedItemFromItemNameList(List<String> itemNameList);
This query gives an "org.springframework.dao.InvalidDataAccessResourceUsageException" and marks the "NOT" as failure.
If I try the same query without NOT ("give all employees who did create a item in item.nameList", the query does what it should.
In this thread Peter Neubauer told that this "NOT IN" exists in cypher: https://groups.google.com/forum/#!topic/neo4j/_PehVUfGaIA
Any idea what is wrong?
NOT is a negation, so you have to do it like this:
WHERE NOT(it.name IN({0}))
Related
I want to implement search by 3 condititions.
if search equal name
if search equal motd (description)
if search is member of ApplicationServer categories.
But I get result only for "member of" even if first or second condition is true.
#Query("Select s from ApplicationServer s where
(s.name like %:search%)
or (s.motd like %:search%)
or (:search member of s.categories)")
Good night, I am working in DB2 and I have been having some troubles making a query with case when
I have to find a way to make a query to define if a record of some category is valid only if the required fields of the relation are required and have been marked as selected, but in this case some registrys are empty and then I must exclude, I have a query like this:
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' then 'Yes'
else 'no'
from category_table
The problem, is that in some category the required field are all false (it's means do not exist) then I must put a condition like the sum equal to cero, but i always get a syntax error. I have something like this,
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' and (count(category_id) where required='true' != 0 ) then 'Yes'
else 'no'
from category_table
I have this problem in db2, saddly I can not put the original query hear because the proxy of my work don't le me pass emails to outside or even login at the web page from there.
I would be grateful for any help.
Have you tried using the VALUE function? if no rows will qualify the case conditions then you'll get Zero in the result.
I'm a total LINQ noob so I guess you'll probably have a good laugh reading this question. I'm learning LINQ to create queries in LightSwitch and what I don't seem to understand is to select an entity based on a value in a lookup table. Say I want to select all employees in a table that have a job title that is picked from a related lookup table. I want the descriptive value in the lookup table for the user to pick from a list to use as a parameter in a query, not the non-descriptive id's.
Can someone point me to an article or tutorial that quickly explains this, or give me a quick answer? I AM reading books and have a Pluralsight account but since this is probably the most extensive knowledge I will need for now a simple tutorial would help me more that watching hours of videos and read thousands of pages of books.
Thanks in advance!
Edit: this is the code. As far as I know this should but won't work (red squigly line under EmployeeTitle, error says that EmployeeContract does not contain a definition for EmployeeTitle even though there is a relationship between the two).
partial void ActiveEngineers_PreprocessQuery(ref IQueryable<Employee> query)
{
query = from Employee e in query
where e.EmployeeContract.EmployeeTitle.Description == "Engineer"
select e;
}
Edit 2: This works! But why this one and not the other?
partial void ActiveContracts_PreprocessQuery(ref IQueryable<EmployeeContract> query)
{
query = from EmployeeContract e in query
where e.EmployeeTitle.Description == "Engineer"
select e;
}
The red squiggly line you've described is likely because each Employee can have 1-to-many EmployeeContracts. Therefore, Employee.EmployeeContracts is actually an IEnumerable<EmployeeContract>, which in turn does not have a "EmployeeTitle" property.
I think what you're looking for might be:
partial void ActiveEngineers_PreprocessQuery(ref IQueryable<Employee> query)
{
query = from Employee e in query
where e.EmployeeContract.Any(x => x.EmployeeTitle.Description == "Engineer")
select e;
}
What this is saying is that at least one of the Employee's EmployeeContracts must have an EmployeeTitle.Description == "Engineer"
Try something like this:
partial void RetrieveCustomer_Execute()
{
Order order = this.DataWorkspace.NorthwindData.Orders_Single
(Orders.SelectedItem.OrderID);
Customer cust = order.Customer;
//Perform some task on the customer entity.
}
(http://msdn.microsoft.com/en-us/library/ff851990.aspx#ReadingData)
Assuming you have navigation properties in place for the foreign key over to the lookup table, it should be something like:
var allMonkies = from employee in context.Employees
where employee.EmployeeTitle.FullTitle == "Code Monkey"
select employee;
If you don't have a navigation property, you can still get the same via 'manual' join:
var allMonkies = from employee in context.Employees
join title in context.EmployeeTitles
on employee.EmployeeTitleID equals title.ID
where title.FullTitle == "Code Monkey"
select employee;
I'm constructing a hql query that needs to return orders where the User's ID is null:
IList<Order> rows = DataContext.LoadList<Order>(
"from Order " +
"where OrderDate < ? " +
" and User.ID is null" //have also tried 'and User is null'
, DateTime.Today.AddMonths(-1));
This returns no records even though a direct query against the db returns a few dozen.
If I use the same query but replace the 'is null' with '33' (a valid userID), I'll get that user's orders. So the foundation of the query is valid - something's wrong with how I'm expressing the 'is null' bit.
Probably has something to do with the fact that, in the .NET project the Order object contains a complex User object where as in the database, the Orders table just holds integer (ID) that's a foreign key to the User table.
Still - since 'and User.ID = 33' works as expected I don't follow why 'is null' doesn't.
This answer suggests I need to switch of the Criteria route. This answer suggests that my current code should work.
thx
Rather than building a query statement, use a Query factory approach:
Query q = new Query();
q.Criteria.Add(new Criteria("User.ID", CriteriaOperator.IsNull));
Works.
I have the following code in Linq to Entity:
var policy= from pol in conn.Policy
where pol.Product.DESCRIPTION=="someProduct"
SELECT pol;
Then, the table Policy, has some dependencies for a table called Entity. If I do this:
foreach(Policy p in policy){
if(!p.Entity.IsLoaded) p.Entity.Load();
IEnumerable<Entity> entities= from ent in p.Entity
Where ent.EntityType.DESCRIPTION=="SomeEntityType"
select ent;
Console.Writeline(entities.ElementAt(0).NAME);
}
It says, "Object not set to an instance", but if I do:
foreach(Policy p in policy){
if(!p.Entity.IsLoaded) p.Entity.Load();
foreach(Entity et in p.Entity)Console.Write(et.NAME);
}
It works!
Can anyone tell me why?
Thank you, Best regards.
I'd say it's because your LINQ statement isn't returning any values, so entities is null.
Your second example works because you're not trying to filter the results.
Do you have some entities that have the DESCRIPTION set to exactly the string (including case)?