OrientDB For Loop - orientdb

I Want To create single query with for loop
For example I have table 1
[id , Name]
[ 1 , X1]
[ 2 , X2]
[ 3 , X3]
And Seconde Table
[id, Name]
[ 5 , Y5]
[ 6 , Y6]
[ 7 , Y7]
All I want is to have new table with followin data
[NewName]
[X1-Y5]
[X1-Y6]
[X1-Y7]
[X2-Y5]
[X2-Y6]
[X1-Y7]
[X3-Y5]
[X3-Y6]
[X3-Y7]
I am failing to create this , I am able to this with only fisrt or alst row of table using first() and last() commands
Thanks in advance

To get the combination you want in a new table try this javascript function:
var g = orient.getGraph();
var table1 = g.command("sql","select from table1");
var table2 = g.command("sql","select from table2");
for(i = 0; i < table1.length; i++)
{
for(j = 0; j < table2.length; j++)
{
g.command("sql","insert into table3(newName) values ('"+ table1[i].getRecord().field("name") +" - "+ table2[j].getRecord().field("name") +"')")
}
}
you can call it in SQL like in this way:
select function_name()
in this way you have a sort of join table, if this is your intent is not the correct way to because there is no JOIN in OrientDB, instead you can use Edge, Link ...
In case you're looking for how to do what you want, you can try this javascript function:
var g = orient.getGraph();
var table1 = g.command("sql","select from table1");
var table2 = g.command("sql","select from table2");
for(i = 0; i < table1.length; i++)
{
for(j = 0; j < table2.length; j++)
{
g.command("sql","create edge connection from "+ table1[i].getId() +" to "+ table2[j].getId() +"")
}
}
as before, you can call it in SQL like in this way:
select function_name()
Hope it helps
Regards

Related

Is there an equivalent in Entity Framework for CASE WHEN SomeCol IS NULL THEN 0 ELSE 1 END

The T-SQL statement is below, essentially I want to return a boolean computed field xmlHasValue
SELECT TOP 10
hrd.pkID
, etc= "etc..."
, xmlHasValue = CASE WHEN hdr.someVeryLongXml IS NULL THEN 0 ELSE 1 END
FROM MyLeftTable hdr
inner JOIN MyRightTable lines ON hdr.pkID = lines.fkID
WHERE hdr.SomeField == 123
ORDER BY hdr.pkID DESC
How can I write this in EntityFramework (Full Fx, not dotnet-core), such that EF produces the Case statement as above?
My attempt:
var query = from hdr in dbCtx.MyLeftTable
join lines in dbCtx.MyRightTable on hdr.pkID equals lines.fkID
where hdr.SomeField == 123
orderby hdr.pkID descending
select new //select into anon C# obj
{
pkID = hdr.pkID,
etc = "etc...",
xmlHasValue = hdr.someVeryLongXml //<== ??? stuck here ???
};
var anonObjList = query.AsNoTracking()
.Take(10)
.ToList(); //exec qry on the SERVER, and fill the anon object.

Filter by Age in EFCore using Postgresql - Npgsql

Is it possible to translate this following Postgresql query to EFCore?
SELECT "applic"."age" FROM (
SELECT EXTRACT(YEAR FROM age(birthdate)) :: int AS "age" FROM public.applicant
) AS "applic"
WHERE "applic"."age" < 50;
I've looked into the documents but I can't find anything helpful.
A solution that works:
var applicants = from s in this.RepositoryContext.Applicants select s;
if (query.AgeStart != null && query.AgeEnd != null)
{
applicants = applicants.Where(c => (DateTime.Today.Year - c.BirthDate.Year) >= query.AgeStart && (DateTime.Today.Year - c.BirthDate.Year) < query.AgeEnd);
}

What to use - While vs Cursor to improve performance of procedure in sybase

I am trying to improve the performance of stored procedure which is currently taking more than 5 hours..
I have done below things to improve performance of this procedure-
-- i have created indexes for each table.
--Instead of count(*), i am using count(1).
But i am just wondering what to use in place of while loop, if possible, Can i use cursor? will there be any impact because i have read cursors do take a lot of time in processing..
Summary of procedure:
- Calculating row count of a table.
- for every row count selecting paramters.
- These parameters are being used by another procedure for the execution.
DECLARE #lnTotalCount INT
SELECT #lnTotalCount = COUNT(*) FROM
firstTable chksts
SELECT #lnRecordCount = 1, #lnRowsProcessed =0
WHILE #lnRecordCount <= #lnTotalCount
BEGIN
-- SET ROWCOUNT 1
SELECT #lcCKPY_REF_ID = ckck.CKPY_REF_ID,
#lnCKCK_SEQ_NO = ckck.CKCK_SEQ_NO,
#lcPYPY_ID = ckck.PYPY_ID,
#lnCKCK_CK_NO = ckck.CKCK_CK_NO,
#ldtCKCK_CASHED_DT = ckck.CKCK_CASHED_DT,
#ldtCKCK_PRINTED_DT = ckck.CKCK_PRINTED_DT,
#ldtCKCK_REISS_DT = ckck.CKCK_REISS_DT,
#lcCKCK_TYPE = ckck.CKCK_TYPE,
#lcCKCK_PAYEE_NAME = ckck.CKCK_PAYEE_NAME,
#lcCKCK_CURR_STS = LTRIM(RTRIM(chksts.[TRANSACTION])),
#lnCKST_SEQ_NO = ckck.CKST_SEQ_NO,
#lcCKCK_REISS_USUS_ID = ckck.CKCK_REISS_USUS_ID,
#lnCKCK_LOCK_TOKEN = ckck.CKCK_LOCK_TOKEN,
#ldtATXR_SOURCE_ID = ckck.ATXR_SOURCE_ID,
#lnBPID_CK_NO = chksts.SERIAL_NUMBER
FROM
firstTable chksts,
secondTable ckck,
thirdTable bpid
WHERE ckck.CKPY_REF_ID = bpid.CKPY_REF_ID
AND bpid.BPID_CK_NO = chksts.SERIAL_NUMBER
AND ckck.CKCK_SEQ_NO = bpid.CKCK_SEQ_NO
AND ckck.CKCK_CURR_STS IN ('03','X3')
AND chksts.ID = #lnRecordCount
IF(##ROWCOUNT<>0) /* 1.5 If-Else condition*/
BEGIN
EXEC #lnRetCd = ABProcedure
NULL,
NULL,
#lcCKPY_REF_ID,
#lnCKCK_SEQ_NO,
#lcPYPY_ID,
#lnCKCK_CK_NO,
#ldtCKCK_CASHED_DT,
#ldtCKCK_PRINTED_DT,
#ldtCKCK_REISS_DT,
#lcCKCK_TYPE,
#lcCKCK_PAYEE_NAME,
#lcCKCK_CURR_STS,
#lnCKST_SEQ_NO,
#lcCKCK_REISS_USUS_ID,
#lnCKCK_LOCK_TOKEN,
#ldtATXR_SOURCE_ID
SELECT #lnRowsProcessed = #lnRowsProcessed + ##ROWCOUNT
SELECT #lnRecordCount = #lnRecordCount + 1

Linq adding new rows to table when there is a relation table

this question is in relation to my previous question: Linq2Entity Getting Values from reference Table
Now i have the problem that i want to add a new entry in Table B. I tried something like this:
ObjectQuery<A> aTable = dbConnection.A;
ObjectQuery<B> bTable = dbConnection.B;
var data = from d in aTable //Reference dataset in Table A
where d.ID == myID
select d;
B bData = new B()
{
ID = GetNewID(),
Text = text,
A = data.First()
};
dbConnection.AddToB(bData);
but this "A = d.First()" does now work... Any ideas? Thx!

Can some one help me to conver it into LINQ i m using Entity Framework

select ForumCategories.ID , ForumCategories.Title , ForumCategories.DateCreated,
CO = ( select COUNT(*) from ForumSubCategories where ForumSubCategories.CategoryID_FK = ForumCategories.ID)
from ForumCategories
var q = from fc in Context.ForumCategories
select new
{
Id = fc.ID,
Title = fc.Title,
DateCreated = fc.DateCreated
CO = fc.ForumSubCategories.Count()
};
return q;
The "join" (subquery) is implicit; it's defined in the relationship between ForumCategories and ForumSubCategories in your model. Using this syntax, the call to Count() will be done on the DB server.