我在“仅代码”模式下使用实体框架 CTP5。我正在对从数据库返回的对象运行 LINQ 查询,因为查询运行速度非常慢。有什么方法可以获取从查询生成的 SQL 语句?
Topic currentTopic =
(from x in Repository.Topics
let isCurrent = (x.StoppedAt <= x.StartedAt || (x.StartedAt >= currentTopicsStartedAtOrAfter))
where x.Meeting.Manager.User.Id == user.Id && isCurrent
orderby x.StartedAt descending
select x).FirstOrDefault();
“存储库”属性是 DbContext 的后代。
这有点复杂,因为 EF 不能在对象上使用我的辅助方法,所以我直接在查询中指定逻辑。
那么,有什么方法可以转储该 LINQ 查询生成的 SQL(例如到我的 log4net 存储库)?