1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
var db = new dbDataContext(); var ems = new string[] { "1@test.com", "2@test.com", "3@test.com", "4@test.com", "5@test.com", "5@test.com", "7@test.com", "8@test.com", "9@test.com" }; var q = db.t_emails.Where(i => i.f_email == "test@test.com" & i.f_name == "John Doe" & i.f_created_date > DateTime.Now & ems.Contains(i.f_email)).AsQueryable(); var c = q.Count(); var tw = new StringWriter(); db.Log = tw; var f = q.FirstOrDefault(); var query = System.Text.RegularExpressions.Regex.Split(tw.ToString(), "-- (@p\\d+:) | (Context:)", System.Text.RegularExpressions.RegexOptions.ExplicitCapture).Select(i => i.Trim()).ToArray(); var input = query.Where(i => i.StartsWith("Input")).Select(i => i.Split("]").First().Split("[").Last()).ToArray(); var s = query[0]; for (var i = input.Length-1; i >= 0; i--) { s = s.RegExReplace("@p" + i, "'" + input[i] + "'"); } Response.Write(s); Response.Write("<br/>"); Response.Write("<br/>"); Response.Write(s); |
Thursday, December 3, 2015
Parse LinqToSql Generated Query and Parameters
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment