var newUser = new tblUser() {
Email = strEmail,
Password = strPassword,
DateBirth = DateTime.Parse(strDateBirth),
};
db.tblUsers.InsertOnSubmit(newUser);
db.SubmitChanges();
我想获得linq生成的实际SQL查询。
答案 0 :(得分:5)
你需要将DataContext.Log属性设置为一个writer,你可以在一个stringbuilder周围包装一个writer然后插入response.write你的stringbuilder.tostring ...
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
Context.Log = writer;
...
DOINSERT & SUBMITCHANGES
...
Response.Write(sb.ToString());
答案 1 :(得分:1)
db.Log是一个TextWriter,可用于获取查询文本。
db.Log = Console.Out
var newUser = new tblUser()
{
Email = strEmail,
Password = strPassword,
DateBirth = DateTime.Parse(strDateBirth),
};
db.tblUsers.InsertOnSubmit(newUser);
db.SubmitChanges();
它会将查询文本写入标准输出。
答案 2 :(得分:1)
检查msdn article。您可以使用DataContext.Log
属性。