我怎麼會在這Linq的SQL查詢轉換,抱歉,但我沒有那麼多專家在LINQ聯盟在數據表
select ConnectionId
from LearnerConnections
where LearnerId = 1
union
select LearnerId
from LearnerConnections
where ConnectionId = 1
也可我寫的數據表梅索德得到的結果(如DataTable.Select( ) 方法)?
在此先感謝
我怎麼會在這Linq的SQL查詢轉換,抱歉,但我沒有那麼多專家在LINQ聯盟在數據表
select ConnectionId
from LearnerConnections
where LearnerId = 1
union
select LearnerId
from LearnerConnections
where ConnectionId = 1
也可我寫的數據表梅索德得到的結果(如DataTable.Select( ) 方法)?
在此先感謝
類似的東西
LearnerConnections.Where(x => x.LearnerId == 1)
.Select(m => m.ConnectionId)
.Union(LearnerConnections.Where(l => l.ConnectionId ==1)
.Select(lc => lc.LearnerId)
);
有一個DataTable,它應該看起來像
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"))
);
願這會有所幫助
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);
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);
如果您使用的是DataTable,則需要使用LINQ to DataSet。這SO question也可能會幫助你。