本文介绍了有没有一种方法,我可以运行Database.SqlQuery为异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下内容:
var sql = @"Select
case when Test.TestTypeId = 1 then Exam.Name
when Test.TestTypeId = 2 then Topic.Name
end as Name,
Test.Title,
Test.TestId,
Test.QuestionsCount
FROM Test
LEFT JOIN Exam ON Test.ExamId = Exam.ExamId
LEFT JOIN Topic ON Test.TopicId = Topic.TopicId
WHERE Test.TestStatusId = 1 -- Current";
var tests = db.Database.SqlQuery<TestDTO>(sql).ToList();
我一直在寻找一个这样的异步方法,但它似乎并不存在。有没有办法,我可以运行此异步的方式?
I was looking for an async method for this but it does not seem to exist. Is there a way that I can run this async?
推荐答案
如果您正在使用实体框架6,你只需要指定
If you're using Entity Framework 6 you just need to specify
using System.Data.Entity;
在你的文件的顶部。
at the top of your file.
ToListAsync
是的IQueryable℃的扩展方法; T&GT;
在 System.Data这声明.Entity.QueryableExtensions
这篇关于有没有一种方法,我可以运行Database.SqlQuery为异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!