0

How I will convert this SQL query in Linq, sorry but I am not that much expert in LINQ

select ConnectionId
from LearnerConnections
where LearnerId = 1
union
select LearnerId
from LearnerConnections
where ConnectionId = 1

also can I write the DataTable methode to get the result (like DataTable.Select() method)?

thanks in advance

4

3 に答える 3

2

そんな感じ

LearnerConnections.Where(x => x.LearnerId == 1)
                  .Select(m => m.ConnectionId)
                  .Union(LearnerConnections.Where(l => l.ConnectionId ==1)
                                           .Select(lc => lc.LearnerId)

                  );

データテーブルを使用すると、次のようになります。

  dtLearnerConnections.AsEnumerable()
                      .Where(m => m.Field<int>("LearnerId") == 1)
                      .Select(m => m.Field<int>("ConnectionId"))
                      .Union(dtLearnerConnections.AsEnumerable()
                                                 .Where(x => x.Field<int>("ConnectionId") == 1)
                                                 .Select(x => x.Field<int>("LearnerId"))
                      );
于 2013-02-05T13:07:24.790 に答える
0

これがお役に立てますように

var results = (from l in LearnerConnections where l.LearnerId == 1 
                 select l.ConnectionId).Union(from a in LearnerConnections 
                 where a.ConnectionId == 1 select l.LeaenerId);
于 2013-02-05T13:07:52.917 に答える
0
var result = (from lc in LearnerConnections
              where lc.LearnerId == 1
              select lc.ConnectionId)
              .Union
             (from lc in LearnerConnections
              where lc.ConnectionId == 1
              select lc.LearnerId);

DataTables を使用している場合、これにはLINQ to DataSetの使用が含まれます。この SOの質問も役立つかもしれません。

于 2013-02-05T13:09:11.933 に答える