Use OpenAccess to generate SQL-Select by Linq-Query

7 posts, 0 answers
  1. Florian
    Florian avatar
    3 posts
    Member since:
    Nov 2011

    Posted 05 Sep 2012 Link to this post

    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.
  2. Adrian
    Adrian  avatar
    15 posts
    Member since:
    Dec 2010
  3. DevCraft banner
  4. Florian
    Florian avatar
    3 posts
    Member since:
    Nov 2011

    Posted 06 Sep 2012 Link to this post

    Hi Neagoe!

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

    Regards,
    Florian
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 06 Sep 2012 Link to this post

    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!
  6. Florian
    Florian avatar
    3 posts
    Member since:
    Nov 2011

    Posted 06 Sep 2012 Link to this post

    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
  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 10 Sep 2012 Link to this post

    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!
  8. Fawad
    Fawad avatar
    38 posts
    Member since:
    May 2009

    Posted 25 Mar 2014 Link to this post

    Old thread but this link can give you trace functionality now.

Back to Top
DevCraft banner