I am trying to write a MATCH statement to pull related data.
CREATE CLASS Member EXTENDS V;
CREATE CLASS DirectVolumes EXTENDS V;
CREATE SEQUENCE dvSequence TYPE ORDERED;
CREATE CLASS GroupVolumes EXTENDS V;
CREATE SEQUENCE groupVolumesSequence TYPE ORDERED;
CREATE CLASS GenerationVolumes EXTENDS V;
CREATE SEQUENCE genGroupVolumesSequence TYPE ORDERED;
CREATE SEQUENCE memberIdSeq TYPE ORDERED;
CREATE VERTEX Member SET id=sequence('memberIdSeq').next();
CREATE VERTEX DirectVolumes set id=sequence('dvSequence').next();
CREATE VERTEX GroupVolumes set id=sequence('groupVolumesSequence').next();
CREATE VERTEX GenerationVolumes set id=sequence('genGroupVolumesSequence').next();
CREATE EDGE OWNS_DV_CURRENT FROM (SELECT FROM Member WHERE id = 1) TO (select from DirectVolumes where id = 1);
CREATE EDGE OWNS_PG_CURRENT FROM (SELECT FROM Member WHERE id = 1) TO (select from GroupVolumes where id = 1);
CREATE EDGE OWNS_GG_CURRENT FROM (SELECT FROM Member WHERE id = 1) TO (select from GenerationVolumes where id = 1);
Now I want Member, andOWNS_DV_CURRENT, OWNS_PG_CURRENT, OWNS_GG_CURRENT edges data together. I have removed properties for simplicity.
What is the right way to do this with a MATCH? I didn't figure out how to fetch multiple related Classes. query seems ok but it returns 0 I think it is looking for OWNS_PG_CURRENT on top of OWNS_DV_CURRENT and not on Member itself.
select from (MATCH {class: Member, as:member}.out("OWNS_DV_CURRENT"){as:dv}.out("OWNS_PG_CURRENT") {as: pg} RETURN member, dv,pg)
Try this:
MATCH
{class: Member, as:member}.out("OWNS_DV_CURRENT"){as:dv},
{as:member}.out("OWNS_PG_CURRENT") {as: pg}
RETURN member, dv,pg
Related
How I am trying to use map to store multiple key value properties. the problem I see is that it doesn't let me store existing data, it overrides data everytime I tried to set a new property.
Create VERTEX Person extends V;
CREATE CLASS Person EXTENDS V;
CREATE PROPERTY Person.name STRING (MANDATORY TRUE, MIN 3, MAX 50);
Create VERTEX Person set name="test";
update ( SELECT from Person where name="test") SET mapField=
{"property1":mapField.property1+10};
set property1 into map, and update it, works just fine.
update ( SELECT from Person where name="test") SET mapField=
{"property1":mapField.property1+30};
select from Person;
Set another property "property2", now I loose the property1.
update ( SELECT from Person where name="test") SET mapField=
{"property2":mapField.property2+10};
select from Person;
is ther a way I can retain previous property and make this work still?
Thanks
Hari
This should do the trick:
update ( SELECT from Person where name="test")
SET mapField.property1 = mapField.property1 + 30;
In V 2.2 there was also an UPDATE PUT option, ie.
update ( SELECT from Person where name="test")
PUT mapField = property1, eval('mapField.property1 + 30');
but it's not supported anymore (and it's definitely ugly)
I have a OrientDB question. For the statement
INSERT INTO Account CONTENT
{ name : 'Luca',
vehicles : {
#class : 'Vehicle',
type : 'Car',
model : 'Maserati',
isItTrue: false
}
}
I get a result (see screenshot), but the class/table 'Vehicle' does not contain any entries. Is this a valid result?
I expected that automatically some values are written into 'Vehicle' and connected to 'Account'. Only the column 'vehicles' from 'Account' contains JSON-Data.
Thank you for your response.
Best regards
Karo
Screenshot OrientDB
With your query you are inserting embedded data into Account, if you want to insert some data into Account and Vehicle, you should do it in different queries and then if you want you can connect them with an edge. See example:
create class Account extends v
create class Vehicle extends v
create class owns extends e
create property Account.name String
create property Vehicle.type String
create property Vehicle.model String
create property Vehicle.isItTrue BOOLEAN
insert into Account(name) values ("Luca")
insert into Vehicle(type, model, isItTrue) values ("Car", "Maserati", false)
create edge owns from (select from Account where name = "Luca") to (select from Vehicle where model = "Maserati")
Alternatively, if you are not looking to create edges and you just want a link from document to document, the below will give you desired results in single insert / transaction while still keeping your json structure for the linked record
create class Account
create class Vehicle
create property Account.vehicles embedded Vehicle
INSERT INTO Account set name = "luca", vehicles = [ {
"#type": "d",
"#class" : "Vehicle",
"type" : "Car",
"model" : "Maserati",
"isItTrue": false
}]
I have an OrientDB document database. I executed the following commands via Studio:
DROP CLASS student;
DROP CLASS studyCourse;
CREATE CLASS student;
CREATE CLASS studyCourse;
CREATE PROPERTY student.Id INTEGER;
CREATE INDEX Student.Id UNIQUE;
CREATE PROPERTY student.surname STRING;
CREATE PROPERTY student.FK_studyCourse_abbreviation STRING;
CREATE PROPERTY studyCourse.abbreviation STRING;
CREATE INDEX studyCourse.abbreviation UNIQUE;
CREATE PROPERTY studyCourse.name STRING;
CREATE LINK student TYPE LINKSET FROM student.FK_studyCourse_abbreviation TO studyCourse.abbreviation INVERSE;
INSERT INTO studyCourse SET abbreviation = 'Inf', name = 'informatics';
INSERT INTO student SET Id = '11111', surname = 'Miller';
UPDATE studyCourse ADD student = (SELECT FROM student WHERE Id = '11111') WHERE abbreviation = 'Inf';
Now I want to select values as described in the manual ( http://orientdb.com/docs/2.1/SQL.html ):
SELECT * FROM studyCourse WHERE student.surname = 'Miller';
There are no records found.
try using contains instead of =
SELECT FROM studyCourse WHERE student.surname contains 'Miller'
this is working for me:
----+-----+-----------+------------+-----------+-------
# |#RID |#CLASS |abbreviation|name |student
----+-----+-----------+------------+-----------+-------
0 |#14:0|studyCourse|Inf |informatics|[1]
----+-----+-----------+------------+-----------+-------
Ivan
Suppose I have a vertex class called PERSON and and an edge Class called father:
CREATE CLASS PERSON EXTENDS V
CREATE CLASS father EXTENDS E
Suppose that I populated PERSON with some records. I also populated father with some records that connect certain records in PERSON to some others records of PERSON (this simply model who is father of who)
I would like to know how the following query would look like in OrientDB?
Find all ancestors of the Person, say p1 (with rid=#10:1)?
create class Person extends V
create class Father extends E
create vertex Person set name = 'grandfather' #12:0
create vertex Person set name = 'father' #12:1
create vertex Person set name = 'person' #12:2
create edge Father from #12:0 to #12:1
create edge Father from #12:1 to #12:2
I believe this is the situation described above. You can:
select from (
traverse in('Father') from #12:2
) where #rid <> #12:2
This will return all the ancestors of the person (#12:2).
I have a statement:
var items = from e in db.Elements
join a in db.LookUp
on e.ID equals a.ElementID
where e.Something == something
select new Element
{
ID = e.ID,
LookUpID = a.ID
// some other data get populated here as well
};
As you can see, all I need is a collection of Element objects with data from both tables - Elements and LookUp. This works fine. But then I need to know the number of elements selected:
int count = items.Count();
... this call throws System.NotSupportedException:
"The entity or complex type 'Database.Element' cannot be constructed in a LINQ to Entities query."
How am I supposed to select values from multiple tables into one object in Entity Framework? Thanks for any help!
You are not allowed to create an Entity class in your projection, you have to either project to a new class or an anonymous type
select new
{
ID = e.ID,
LookUpID = a.ID
// some other data get populated here as well
};
Your code doesn't work at all. The part you think worked has never been executed. The first time you executed it was when you called Count.
As exception says you cannot construct mapped entity in projection. Projection can be made only to anonymous or non mapped types. Also it is not clear why you even need this. If your class is correctly mapped you should simply call:
var items = from e in db.Elements
where e.Something == something
select e;
If LookupID is mapped property of your Element class it will be filled. If it is not mapped property you will not be able to load it with single query to Element.