[英]Linq to Sql One to many relationship string.join
对于一本书中有多位作者的情况,我想以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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.