2016-08-04 96 views
1

我想查看在LINQ查詢中生成的SQL。查看在ASP.NET Core中使用LINQ時生成的SQL

Question GetLatestPoll = 
    _contextService 
    .Find<Question>(q => q.Status == PollStatus.Open || (q.Status == PollStatus.Review) 
     && ((q.Availability == PollAvailability.All) 
     || (q.Availability == PollAvailability.Company && q.User.ClientId == currentUser.ClientId) 
     || (q.Availability == PollAvailability.Company && q.User.DepartmentId == currentUser.DepartmentId)) 
     && !q.Answers.Any(a=>a.UserId == currentUser.Id)) 
    .Include(q => q.Options) 
    .OrderByDescending(q => q.CreatedAt) 
    .FirstOrDefault(); 

我想使用類似var sql =Context.GetCommand(GetLatestPoll).CommandText;

但名稱上下文中不存在的核心。

`

回答

1

我不能肯定地說有關.NET的核心,但LINQ2SQL數據上下文有Log財產,你可以指定一個TextWriter對象,將收到SQL輸出。