문제

I've got 3 dataset objects that are nested with each other using entity set objects. I am selecting the data like this

var newList = from s in MainTable
from a in s.SubTable1 where a.ColumnX = "value"
from b in a.Detail where b.Name = "searchValue"
select new {
    ID = s.ID,
    Company = a.CompanyName,
    Name = b.Name,
    Date = s.DueDate
    Colour = b.Colour,
    Town = a.Town
};

and this works fine, but the trouble is there are many records in the Detail object-list/table for each Name value so I get a load of duplicate rows and thus I only want to display one record per b.Name. I have tried putting

group s by b.Name into g

before the select, but then this seems to stop the select enabling me to select the columns I want (there are more, in practice). How do I use the group command in this circumstance while still keeping the output rows in a "flat" format?

도움이 되었습니까?

해결책

Appending comment as answer to close question:- Of course that if you group your results, you cant get select a column of a child, thats because there may be more than one childs and you have to specify an aggregate column for example the sum,max etx –

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top