This is a migrated thread and some comments may be shown as answers.

Use OpenAccess to generate SQL-Select by Linq-Query

6 Answers 194 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Florian
Top achievements
Rank 1
Florian asked on 05 Sep 2012, 01:10 PM
I found out, that your OpenAccess is a very advanced Linq-Provider. I'd like to use it to generate SQL-Selects.
Is is possible to just get the sql-command that would be used to query the database by executing the IQueryable<Entity> query?

I'd like to use this query to execute it directly on the server using an insert into .. select ... command-chain without the unecessary traffic back and forth to the client.

Any suggestions would be appreciated.

6 Answers, 1 is accepted

Sort by
0
Adrian
Top achievements
Rank 2
answered on 05 Sep 2012, 10:59 PM
0
Florian
Top achievements
Rank 1
answered on 06 Sep 2012, 07:08 AM
Hi Neagoe!

Thanks for your answer which unfortunately doesn't answer my question ;-) (Or I didn't get it)

Regards,
Florian
0
Alexander
Telerik team
answered on 06 Sep 2012, 02:58 PM
Hello Florian,

You can just call ToString() on the Linq query to get the SQL statement which would be executed on the server. Any parameter values, however, would not be included in this string, so you may have to add them manually. Here is an example how to obtain the SQL:
EntitiesModel context = new EntitiesModel();
 
var query = context.Categories.Where(c => c.CategoryID == 2);
string sql = query.ToString();

Regards,
Alexander
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Florian
Top achievements
Rank 1
answered on 06 Sep 2012, 03:09 PM
Alexander, thanks for your answer.
I'll see, it that fits my needs.
I thought there would be a way to get the parametrized dbCommand.

Regards,
Florian
0
Alexander
Telerik team
answered on 10 Sep 2012, 02:47 PM
Hi Florian,

I am afraid that there is no way to obtain the dbCommand that OpenAccess uses internally. The ToString() trick is the only option at the moment.

Kind regards,
Alexander
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Fawad
Top achievements
Rank 1
answered on 25 Mar 2014, 03:24 PM
Old thread but this link can give you trace functionality now.

Tags
LINQ (LINQ specific questions)
Asked by
Florian
Top achievements
Rank 1
Answers by
Adrian
Top achievements
Rank 2
Florian
Top achievements
Rank 1
Alexander
Telerik team
Fawad
Top achievements
Rank 1
Share this question
or