converting LINQ to Regular queries

4 posts, 0 answers
  1. Grace Manasseh
    Grace Manasseh avatar
    10 posts
    Member since:
    Mar 2010

    Posted 26 Mar 2010 Link to this post

    Is there a way to convert the LINQ queries (while debugging) to regular queries?
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 26 Mar 2010 Link to this post

    Hello Grace Manasseh,

    To convert a specified Linq query to the corresponding sql query you should call the ToString method on the query. In case you use the Telerik OpenAccess DataContext you should the following:

    var query = context.Categories.Where(c => c.CategoryName.Contains("a"));
    string result = query.ToString();

    //SELECT a.[CategoryID] AS COL1 FROM [Categories] a WHERE a.[CategoryName] LIKE '%a

    otherwise:

    var query = scope.Extent<Category>().Where(c => c.CategoryName.Contains("a"));
    string result = query.ToString();
     
    //SELECT a.[CategoryID] AS COL1, a.[CategoryName] AS COL2, a.[Description] AS COL3 FROM [Categories] a WHERE a.[CategoryName] LIKE '%a%'

    I hope that will help you.

    Greetings,
    Damyan Bogoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Grace Manasseh
    Grace Manasseh avatar
    10 posts
    Member since:
    Mar 2010

    Posted 29 Mar 2010 Link to this post

    I'm using ORM, but it's not working.
    A sample query is as follows:

     

    IEnumerable<PLTExclusionDTO> qry = from texclusion in scope.Extent<Pltexclusion>()

     

     

    join exclusions in scope.Extent<Plexclusion>()

     

     

    on texclusion.Plexclusionid equals exclusions.Plexclusionid

     

     

    join terms in scope.Extent<Plterm>()

     

     

    on texclusion.Pltermid equals terms.Pltermid

     

     

    where (terms.Pltermid == vTermId || -1 == vTermId)

     

     

    select new PLTExclusionDTO()

     

    {

    PLTExclusionId = texclusion.Pltexclusionid,

    PLTermId = texclusion.Pltermid,

    PLExclusionId = texclusion.Plexclusionid

    };

  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 29 Mar 2010 Link to this post

    Hi Grace Manasseh,

    You should explicitly call the ToString() method for the qry variable in order to preview the generated SQL query:
    qry.ToString()

    You can very easily test this within the Quick Watch window of Visual Studio.
    I hope this helps.

    Sincerely yours,
    Damyan Bogoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top