This is a migrated thread and some comments may be shown as answers.

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'

1 Answer 611 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Duncan
Top achievements
Rank 2
Duncan asked on 07 Sep 2011, 07:36 PM
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

1 Answer, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 13 Sep 2011, 09:38 AM
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 >>

Tags
LINQ (LINQ specific questions)
Asked by
Duncan
Top achievements
Rank 2
Answers by
Ady
Telerik team
Share this question
or