一对多关系字符串.join
本文关键字:join 字符串 关系 一对多 | 更新日期: 2023-09-27 18:06:33
对于同一本书有多个作者。我想取json格式的值得到json为
"AuthorName":"{ AuthorName = Author1 },{ AuthorName =Author2 }",
但是我需要把它放到
"AuthorName":Author1,Author2
格式。我能做到吗?这是我的查询
var jsonData = from w in bookData
join b in barcodes on w.Id equals b.BookId
select new
{
w.AccessionNo,
AuthorName=string.Join(",", from a in bookAuthor
where a.BookShelfId == w.Id
select new {
a.Authors.AuthorName
}),
w.BookInfoId,
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
尝试选择字符串而不是匿名对象,如下所示:
var jsonData = from w in bookData
join b in barcodes on w.Id equals b.BookId
select new
{
w.AccessionNo,
AuthorName=string.Join(",", from a in bookAuthor
where a.BookShelfId == w.Id
select a.Authors.AuthorName
),
w.BookInfoId,
};
return Json(jsonData, JsonRequestBehavior.AllowGet);