var newUser = new tblUser() {
Email = strEmail,
Password = strPassword,
DateBirth = DateTime.Parse(strDateBirth),
};
db.tblUsers.InsertOnSubmit(newUser);
db.SubmitChanges();
我想获取 linq 生成的实际 SQL 查询。
您需要将 DataContext.Log 属性设置为编写器,您可以将编写器包装在 stringbuilder 周围,然后在插入 response.write your stringbuilder.tostring ...
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
Context.Log = writer;
...
DOINSERT & SUBMITCHANGES
...
Response.Write(sb.ToString());
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();
它会将查询文本写入标准输出。
检查这篇msdn 文章。你可以使用DataContext.Log
属性。