How do I view the SQL generated by the Entity Framework?

后端 未结 22 2822
别那么骄傲
别那么骄傲 2020-11-21 05:35

How do I view the SQL generated by entity framework ?

(In my particular case I\'m using the mysql provider - if it matters)

22条回答
  •  孤街浪徒
    2020-11-21 06:08

    To have the query always handy, without changing code add this to your DbContext and check it on the output window in visual studio.

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.Log = (query)=> Debug.Write(query);
        }
    

    Similar to @Matt Nibecker answer, but with this you do not have to add it in your current code, every time you need the query.

提交回复
热议问题