I seem to be needing to “re-order” my result set after i make some modifications to it, is this “a feature” if so, some enlightenment? am I missing something?
//need the "IN" type functionality to limit my initial set.
var resultSet = from t in someContext.SomeEntities
.Where("it.some_id IN{" + string.Join(",", array) + "}")
where t.obj_id == objtId
orderby t.tInt
select new customObj
{
prop1= t.t1,
prop2 = t.tInt,
prop3 = t.tInt2
};
//Do some other lookups / decision branching and
//determine that i need to remove the following:
//just for arguments sake
resultSet.ToList().RemoveAll(o => o.prop1== 8
&& o.prop1 == 5
&& o.prop1 == 11
&& o.prop1 == 21);
foreach (var vals in resultSet)
{
//do something that depends on the order
}
after that sequence.. something that i expected to be in order, is not.. when i do another orderby on the result set like:
foreach (var vals in resultSet.OrderBy(o => o.tInt))
{
//now the order's okay
}
then it’s what i would’ve originally expected..
so should i not do any ordering until i have filtered my result set down? In this case obviously i could’ve done some filtering on the initial query, but in my situation, i really cant..
..thanks in advance.
UPDATE:
I must be doing a .ToList() on it for the (.RemoveAll()), is that the culprit then?
http://msdn.microsoft.com/en-us/library/wdka673a%28v=vs.90%29.aspx
IMO I think you should remove the initial
orderby t.tIntand do an order by once you have filtered the list with your line:I have never heard of
RemoveAll()changing the order but it is very possible. Either way it will be more efficient to sort fewer records in the long run. I almost always do my sorting after I have filtered things.Hope this helps.