This question is locked. New answers and comments are not allowed.
Grace Manasseh
Top achievements
Rank 1
Grace Manasseh
asked on 26 Mar 2010, 04:46 PM
Is there a way to convert the LINQ queries (while debugging) to regular queries?
3 Answers, 1 is accepted
0
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:
otherwise:
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.
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.
0
Grace Manasseh
Top achievements
Rank 1
answered on 29 Mar 2010, 08:48 AM
I'm using ORM, but it's not working.
A sample query is as follows:
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
};
0
Hi Grace Manasseh,
You should explicitly call the ToString() method for the qry variable in order to preview the generated SQL query:
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.
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.