Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Linq to Entities can you convert an IQueryable into a string of SQL?

eg.

var result = myObject.Where(x => x.prop == 5);

string s = result.toSQL();

Result:

s is "SELECT * FROM [myObjects] WHERE prop = 5"

like image 661
NibblyPig Avatar asked Feb 19 '23 23:02

NibblyPig


1 Answers

If it's IQueryable/ObjectQuery you can use ToTraceString. If it's IDbSet/DbSet you can use ToString directly.

like image 107
cincura.net Avatar answered Feb 23 '23 02:02

cincura.net