An expression of type XXXX is not allowed in a subsequent from clause in a query expression with source type 'System.Linq.IQueryable<XXXX>'. Type inference failed in the call to 'SelectMany'

2 posts, 0 answers
  1. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 07 Sep 2011 Link to this post

    I am getting the following error:

    An expression of type XXXX is not allowed in a subsequent from clause in a query expression with source type 'System.Linq.IQueryable<XXXX>'.  Type inference failed in the call to 'SelectMany'

    I am extremely new to LINQ. I have been using SQL queries with the Open Access SQL API which has been working great. But I want to learn to use LINQ so I a researching and forcing myself to do this.

    I found the following articles which describes how LINQ handles relationships between tables. This is where I was struggling the most and this article does a great job of explaining it. http://msdn.microsoft.com/en-us/library/bb386932.aspx
    So I am trying to duplicate this, but using OpenAccess ORM.

    So this is my query:

    var idQuery = from u in dbContext.Users
                  from c in u.UserGroups
                  where u.CredentialsID == 0
                  select new
                  {
                      u.UserID,
                      u.FirstName,
                      u.MiddleName,
                      u.LastName,
                      u.Gender,
                      u.Birthday,
                      u.CreatedOn
                  };

    u.UserGroups is throwing the error. Intelisense shows me the UserGroups object but doesn’t like something I am doing… Would someone be able to help me identifying what is causing this error please…

    Thanks in advance.

    Duncan
  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 13 Sep 2011 Link to this post

    Hello Duncan,

    It seems that like u.UserGroups is a single object and the from clause expects a sequence of objects. Is u.UserGroups a queryable type that implements IEnuerable or IEnumerable<T>? You can find additional informatio here.
    Alternatively you could modify your query to the following at it would work but I am not sure that is the result you expect

    var idQuery = from u in dbContext.Users
                  let c = u.UserGroups
                  where u.CredentialsID == 0
                  select new
                  {
                      u.UserID,
                      u.FirstName,
                      u.MiddleName,
                      u.LastName,
                      u.Gender,
                      u.Birthday,
                      u.CreatedOn
                  };

    Do get back in case you need further assistance


    Regards,
    Ady
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
Back to Top