我有如下所示的主要选择:
protected IQueryable<Answers> GetActualAnswers<TAns>(DateTime? start, DateTime? end, long? statusId) where TAns: AnswersBase
{
_contex.Set<TAns>.Where(x => x.Type == VoteType.Good)
.Select(vv => new Answers
{
CreatedAt = vv.CreatedAt,
StatusId = vv.StatusId,
Type = vv.Type ,
AnswerInGuideStatusId = vv.AnswerInGuideStatusId
}
}
我在两个简单的查询中使用此方法:
var result1 = GetActualAnswers<JournalAnswers>(start, end, statusId)
.Select(j => new UnitedAnswers
{
Question = j.Question,
}
var result2 = GetActualAnswers<BoAnswers>(start, end, statusId)
.Select(b => new UnitedAnswers
{
Prospects = b.Prospects ,
}
var mainResult = result1.Concat(result2);
我收到错误:
Sql = Sql = '((System.Data.Entity.Infrastructure.DbQuery<UnitedAnswers>)result1).Sql' threw an exception of type 'System.NotSupportedException'
Sql = Sql = '((System.Data.Entity.Infrastructure.DbQuery<UnitedAnswers>)result2).Sql' threw an exception of type 'System.NotSupportedException'
Sql = Sql = '((System.Data.Entity.Infrastructure.DbQuery<UnitedAnswers>)mainResult).Sql' threw an exception of type 'System.NotSupportedException'
是否可以使用多个选择?可能有人可以对此查询提供建议吗?
答案 0 :(得分:0)
首先,我想知道属性j.Question
和b.Prospects
的位置,而在方法GetActualAnswers
中却没有获得2个属性的值以上。
其次,您在方法GetActualAnswers
中返回了IQueryable
,因此应检查empty
而不是null
的值
那么您的案子可能看起来像这样
var mainResult = Enumerable.Concat(
resut1 ?? Enumerable.Empty<UnitedAnswers>(),
resut2 ?? Enumerable.Empty<UnitedAnswers>()
或
var mainResult = Enumerable.Concat(
result1.AsEnumerable(),
result2.AsEnumerable());
以下链接对您有用。