所以我有两个表的布局像(但没有命名):
Table A
-------
AID
Title
ACol1
ACol2 ... (to ACol60)
和
Table B
-------
BID
AID
Title
BCol1
BCol2 ... (to BCol30)
我构建了一个简单的类
public class SimpleCollection
{
public Guid ID { get; set; }
public string Title { get; set; }
public IEnumerable<SimpleCollection> Elements { get; set; }
}
我想做的是双重的:
我尝试了以下内容:
var query = from A in dbContext.TableA
from B in A.TableB
select new SimpleCollection()
{
ID = A.AID,
Title = A.Title,
Elements = select new SimpleCollection<string>()
{
ID = B.BID,
Title = B.Title
}
};
但它不喜欢将Elements设置为select语句。
答案 0 :(得分:1)
var query = from A in dbContext.TableA
from B in A.TableB
group B by A into g
select new SimpleCollection()
{
ID = g.Key.AID,
Title = g.Key.Title,
Elements = g.Select(x => new SimpleCollection {ID = x.BID, x.Title}).ToList()
};
答案 1 :(得分:1)
我相信我在想这个问题。
var query = dbContext.TableA
.Select(p => new SimpleCollection()
{
ID = p.AID,
Title = p.Title,
Elements = p.TableBs
.Select(c => new SimpleCollection()
{
ID = c.BID,
Title = C.Title
}
}