跟踪linq to entity 转成的 sql

  void intializeControlsDataSource()
        {

            using (var db = new NoteBookContext())
            {

                //跟踪linq to entity
                db.Database.Log = logWrite;
                var queyr4 = from q in new RecordService().GetNoteRecordRefList()
                             join u in db.Users on q.userID equals u.userID
                             select new { q.requesteDate, q.voucherNo, q.itemName, u.name };

                
                dgv_recordRef.DataSource = queyr4.ToList();

            }


        }
跟踪代码
 private static void logWrite(string logString)
        {
            string path = @"MyTest2.txt";

            //Create the file.
            using (FileStream fs = new FileStream(path, FileMode.Append))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                   

                        sw.WriteLine("{0}	,{1}", DateTime.Now.ToString(), logString);

                }
            }
        }
日志代码

最终结果:

原文地址:https://www.cnblogs.com/windy3417/p/14335940.html