1

While editing my Repository class an Error pops out

 var applicantList = (from a in context.Profiles
                             join app in context.APPLICANTs
                                on a.PROFILE_ID equals app.Profile_id into joined
                              from j in joined.DefaultIfEmpty()//.OrderBy(v => v.APPLICANT_ID)
                             select j //<--  this is APPLICANTs type
                               ).Take(1000);

   applicantdata = applicantList
                  .SelectMany(c => c.APPLICANTs) //this line added
                  .AsQueryable().OrderBy(v => v.APPLICANT_ID).ToList();

                if (applicantdata.Any())
                {
                    Cache.Set("applicants", applicantdata, 30);
                }
            }
            return applicantdata;

Im having an exception at

.SelectMany(c => c.APPLICANTs) //this line added

saying that :

The type arguments for method 'System.Linq.Queryable.SelectMany(System.Linq.IQueryable, System.Linq.Expressions.Expression>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly

abc123
  • 17,855
  • 7
  • 52
  • 82
Enrique Gil
  • 754
  • 4
  • 19
  • 50

2 Answers2

4

SelectMany accepts a collection of object which each of them have a collection property inside.

You selected APPLICANTs collection at the first statement and running a SelectMany on it doesn't seem to be meaningful.

Checkout these links to understand the SelectMany better.

http://msdn.microsoft.com/en-us/library/bb534336.aspx
Difference Between Select and SelectMany

Community
  • 1
  • 1
Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
1

SelectMany is used for 'flattening' a list of lists. You don't have a list of lists here. You have a list of anonymous joined rows.

It's a bit difficult to infer what you're querying for, but if you're looking to get the related rows (the APPLICANTs rows), you can use this:

var applicantList = (from a in context.Profiles
                     join app in context.APPLICANTs
                     on a.PROFILE_ID equals app.Profile_id
                     select app).Take(1000)
Christopher Stevenson
  • 2,843
  • 20
  • 25
  • what am i trying to do is like this http://stackoverflow.com/questions/4497086/linq-left-join-and-right-join – Enrique Gil May 20 '13 at 07:19
  • `var applicantList = (from a in context.Profiles join app in context.APPLICANTs.DefaultIfEmpty() on a.PROFILE_ID equals app.Profile_id select new { prop1 = a.column1, prop2 = app.column1 }).Take(1000);` – Christopher Stevenson May 20 '13 at 07:22
  • 1
    Here's a more detailed reference: http://codingsense.wordpress.com/2009/03/08/left-join-right-join-using-linq/ – Christopher Stevenson May 20 '13 at 07:23
  • The important parts are the `.DefaultIfEmpty()` on the joined table, which is how you make this a left join (instead of a join), and the `select new { ... }` which will make an anonymous class with the specified properties. You could just as easily declare a class to hold the data, and use `select new MyClassName { ... }`. – Christopher Stevenson May 20 '13 at 07:27
  • sir i will declare my Applicant and Profile class so can help me more – Enrique Gil May 20 '13 at 07:56