If you think that all lines are equal, if they have equal fields:
var s = (from p in _dataBaseProvider.SelectPjdGatewayLineChanged(selectedSourcePlant.LPS_Database_ID) select new PjdGatewayLineChanged() { LineId = p.LineId, LpsLineNo = p.LpsLineNo, LineIdChanged = p.LineIdChanged }) .GroupBy(p => p.LineId) .Select(p => p.First());
You group your identifier, and then for each group you take the first line.
or, more compact,
var s = from p in _dataBaseProvider.SelectPjdGatewayLineChanged(selectedSourcePlant.LPS_Database_ID) group p by p.LineId into q let r = q.First() select new PjdGatewayLineChanged() { LineId = r.LineId, LpsLineNo = r.LpsLineNo, LineIdChanged = r.LineIdChanged };
Thus, the creation of PjdGatewayLineChanged was carried over to the last step (after choosing the right groupby βcandidateβ.
source share