1
SFC.OrderFormModifiedMonitoringRecords
   .SelectMany(q => q.TimeModify, w => w.DateModify)
   .Distinct()
   .OrderBy(t => t)
   .SelectMany(t => new { RowID = t.rowID, OFnum = t.OFNo });

It's Error did i missed something or is it Completely Coded The Wrong Way? After this i'm gonna use this on a Foreach method to gather up multiple data without the duplicates.

3
  • 3
    what is the error? where is the error? Commented Aug 22, 2013 at 6:37
  • It's in this Statement { SFC.OrderFormModifiedMonitoringRecords.SelectMany(q => q.TimeModify, w => w.DateModify) } it says try specifying the type of argument explicity i did specify it right? or did i miss something? :( Commented Aug 22, 2013 at 6:44
  • The error you are getting is suggesting that the compiler can't figure out what the return type of SelectMany is. Thus it asks you to be explicit. Ie, use Selectmany<TypeA,TypeB>( ) . Doing this will not solve the problem, but you will get a clearer error message. If you want us to help you, you must tell us more about the types. What is the type of TimeModify and DateModify and what do you expect the data to look like after the SelectMany statement (before distinct)? Commented Aug 22, 2013 at 6:59

1 Answer 1

4

The delegate you pass to SelectMany must return an IEnumerable and is for collapsing multiple collections into one. So yes, something's definitely wrong here. I think you've confused it with Select which simply maps one collection to another.

Without knowing what your goal is, it's hard to know exactly how to fix it, but I'm guessing you want something like this:

SFC.OrderFormModifiedMonitoringRecords
   .OrderBy(t => t.DateModify)
   .ThenBy(t => t.TimeModify)
   .Select(t => new { RowID = t.rowID, OFnum = t.OFNo })
   .Distinct();

Or in query syntax:

(from t in SFC.OrderFormModifiedMonitoringRecords
 orderby t.DateModify, t.TimeModify
 select new { RowID = t.rowID, OFnum = t.OFNo })
.Distinct();

This will order the records by DateModify then by TimeModify, select two properties, rowID and OFNo and return only distinct pairs of values.

Sign up to request clarification or add additional context in comments.

2 Comments

I believe that .OrderBy(...) should be last, preceded by .Distinct().
@maremp Then you wouldn't be able to order the results because the Select doesn't include the relevant properties.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.