0

I'm trying to query a view with linq and I need help on this. The view returns the following structure :

ID Col1 Col2 Col3

1   A    B    1
1   A    B    2
1   A    B    3
1   A    B    4

etc...

I have an Entity which has a list as a field

class MyEntity {
    int _col1;
    string _col2;
    List<int> _col3 = new List<int>();
}

How can I get fill the list and get all the entities "MyEntity" at the same time?

My attempts is not complet that's why i asked :

List<MyEntity> allObjects = (from d in _dc.myView
 where id==1 %% col1==A && cole2==B
select new MyEntity(d.id,d.col1,d.col2)).Distinct().List();

Thank you,

Bes-m M-bes
  • 177
  • 1
  • 4
  • 16

1 Answers1

0

I don't full understand the question, but it looks like you need a GROUP BY query. Here's how to do this in LINQ query syntax:

MyEntity entity = from e in objectContext.yourTableName
                  group e by new { e.Col1, e.Col2 } into grp
                  select new MyEntity
                  {
                      _col1 = grp.Key.Col1,
                      _col2 = grp.Key.Col2,
                      _col3 = grp.Select(e => e.Col3).ToList()
                  };
Connell
  • 13,925
  • 11
  • 59
  • 92