我正在编写一个 LINQ 查询以将现有列表与当前查询匹配。但它向我显示了类似这样的错误(无法创建类型为“Vibrant.Areas.Acquisition.Models.BibContentsModel”的常量值。在此上下文中仅支持原始类型(“例如 Int32、String 和 Guid”)。)。请帮我找出问题所在。
代码
FinalRRidInt = FinalRRid.Select(int.Parse).ToList();
List<BibContentsModel> InitData = RRData().ToList();
var FinalModel = (from aa in db.RecommendResources
where FinalRRidInt.Contains(aa.Id)
select new
{
RRId = aa.Id,
CurrentTitle = aa.Title,
CurrentISBN = aa.ISBN,
CurrentAuthor = aa.Author,
NewBibContentsModel = (from rr in InitData
where rr.Title.Contains(aa.Title) || rr.ISBN.Contains(aa.ISBN)
select new BibContentsModel
{
RRId = aa.Id,
BibId = rr.BibId,
Title = rr.Title,
ISBN = rr.ISBN,
Author = rr.Author,
}).GroupBy(asd => asd.BibId).Select(asd => asd.FirstOrDefault())
}).AsEnumerable().Select(x => new RRModel
{
RRId = x.RRId,
CurrentAuthor = x.CurrentAuthor,
CurrentISBN = x.CurrentISBN,
CurrentTitle = x.CurrentTitle,
NewBibContentsModel = x.NewBibContentsModel.ToList()
});
InitData列表的Sql查询方法
public List<BibContentsModel> RRData()
{
List<BibContentsModel> Initdata = db.ExecuteStoreQuery<BibContentsModel>("select distinct b.id as BibId, stuff((select ' ' + bcc.NormValue from BibContents as bcc where bcc.BibId = b.Id and bcc.TagNo = '245' FOR XML PATH('') ), 1, 1, '') as Title,(select top(1) Normvalue from bibcontents bcon where (bcon.tagno='020' or bcon.tagno='022') and bcon.sfld='a' and bcon.bibid=b.id) as ISBN,(select top(1) Normvalue from bibcontents bcon where bcon.tagno='100' and bcon.sfld='a' and bcon.bibid=b.id) as Author from bibs b left join bibcontents bc on b.id=bc.bibid").ToList();
return Initdata;
}
谢谢