kiran madiraju

kiran madiraju

  • NA
  • 1
  • 778

Entity Frame work 6.0 capturing raw sql

Jun 2 2015 10:06 PM
can you please help to capture raw sql after parameter binding so that i can save and run same sql's in test and prod environment
please let me know if there is alternative ways to accomplish  this
Thanks
//enable logging
public PcatAdminContext()
: base("name=PcatAdminContext")
{
Database.Log = WriteFile.WriteSQL;
}
//write SQL method
public static void WriteSQL(string data)
{
string path = @"c:\SQLtrace.txt";
File.AppendAllText(path, data);
}
//linq query
DESTINATION des = db.DESTINATION.Single(u => u.DESTINATION1 == destination.Destination1);
des.CLASS_RANGE = destination.ClassRange;
db.SaveChanges();
//update statement output looks like this
Started transaction at 6/2/2015 6:03:10 PM -06:00
update "PCAT_ADMIN_TOOL"."DESTINATION"
set "CLASS_RANGE" = :p0
where ("DESTINATION" = :p1)
-- :p0: 'Class Range A' (Type = String, Size = 20)
-- :p1: 'test' (Type = String, Size = 200)
-- Executing at 6/2/2015 6:03:10 PM -06:00
-- Completed in 86 ms with result: 1
//expected output
update "PCAT_ADMIN_TOOL"."DESTINATION"
set "CLASS_RANGE" = 'Class Range A'
where ("DESTINATION" = 'test')