过去几天我一直在努力解决 linq 查询性能问题:
LinqConnectionDataContext context = new LinqConnectionDataContext();
System.Data.Linq.DataLoadOptions options = new System.Data.Linq.DataLoadOptions();
options.LoadWith<Question>(x => x.Answers);
options.LoadWith<Question>(x => x.QuestionVotes);
options.LoadWith<Answer>(x => x.AnswerVotes);
context.LoadOptions = options;
var query =( from c in context.Questions
where c.UidUser == userGuid
&& c.Answers.Any() == true
select new
{
c.Uid,
c.Content,
c.UidUser,
QuestionVote = from qv in c.QuestionVotes where qv.UidQuestion == c.Uid && qv.UidUser == userGuid select new {qv.UidQuestion, qv.UidUser },
Answer = from d in c.Answers
where d.UidQuestion == c.Uid
select new
{
d.Uid,
d.UidUser,
d.Conetent,
AnswerVote = from av in d.AnswerVotes where av.UidAnswer == d.Uid && av.UidUser == userGuid select new { av.UidAnswer, av.UidUser }
}
}).ToList();
查询必须运行 5000 行,最多需要 1 分钟。如何提高此查询的性能?
更新: