I have a table similar to below:
Data {
id varchar(50),
pId uniqueidentifier ,
fId uniqueidentifier ,
xid uniqueidentifier,
flag smallint
}
The table contains a lot of duplicate rows since pId and fId is a 1:n relationship and fId to xId is a 1:n relationship too.
I want to query this table and populate a obj as below:
class P
{
Guid id;
List<F> fList;
}
class F
{
Guid id;
List<X> xList;
}
class X
{
Guid id;
byte flag;
}
I am learning Linq. Any solutions using Linq to populate class P from the table would be helpful.
Thanks!
This query will return
IEnumerable<P>(not sure about convertingsmallinttobooleanbut other stuff should work)Comments:
gpwill contain all rows corresponding to some pId, in other words – it returns all fId, which related to pId.gfwill contain all rows from previous result which relate to some fId (i.e. all xids related to fId)