http://www.myexception.cn/linq/1288046.html
Entity framewok 怎么实现多条记录作为一条取出, for xml path怎么实现
News表:
ID Title
1 'ABCDE'
2 'ABC'
Category表:
ID CategoryName
1 '类型1'
2 '类型2'
3 '类型3'
CatNew表:
ID NewsID CategoryID
1 1 1
2 1 2
3 2 3
4 2 1
怎么输出这样的数据:
1 'ABCDE' 类型1_类型2
2 'ABC' 类型3_类型1
------解决方案--------------------
你可以利用ExecuteStoreCommand方法直接执行sql语句.
------解决方案--------------------
var query = from n in db.News
from c in db. Category
from t in db. CatNew
where n.ID == t.NewsID && c.ID == t.CategoryID
group c by n.Title into q
select new { q.Key, m1 = string.Join(",",q.Select(x=>x.CategoryName).ToArray()) };