locked
Custom query, Enumeration yields no results RRS feed

  • Question

  • Hi folks,

    I have written the following code

     

     partial void TeamsNotIncludedInGameDay_PreprocessQuery(int? GameDayId, ref IQueryable<Team> query)
            {
                GameDay gd = GetGamedayById(GameDayId);

                var quAllTeams = AllTeams();
                var quHomeTeams = from g in gd.Games
                                  select g.HomeTeam;
                var quAwayTeams = from g in gd.Games
                                  select g.AwayTeam;

                var quIncluded = quAwayTeams.Union(quHomeTeams);
                var idsIncluded = from t in quIncluded
                                  select t.Id;

                query = from t in query 
                        where idsIncluded.ToList().Contains(t.Id) == false
                        select t;

            }

     

    query is always empty. LS states that enumeration yielded no results. Is it not possible to base a query on other temporary lists that are created within the query code? If yes, what am I doing wrong?

    The code is to assemble a gameday with matchups. Whenever a team has been selected, I want to exclude it from all other lists.

     

    Monday, July 4, 2011 5:22 PM

Answers

  • Holger,

    The PreProcessQuery method is fairly restricted in what you can do in it.

    For example you can can ONLY filter the records that are in the query parameter (which I see is what you're *trying* to do).

    You can't "add" records etc (& I know you're not trying to do that, I only mention it for completeness).

    The article that Jaime provided a link for is "joining" only in the sense that it's using related entities (navigation properties).

    Even though you're using a .ToList to attempt to "force" materialisation of your idsIncluded collection, that doesn't seem to be enabled in PreProcessQuery, so your collection will always be empty.

    Unless you can rethink your logic, to use only the entities in the query, or any of their related properties, you won't be able to do what you're trying to do in PreProcessQuery.

    You may need to invest a little time in a custom RIA service, assuming that you have VS Pro, or higher, not just stand-alone LS.

    If you need some background, or think it's "too difficult", have a look at How Do I: Display a Chart Built On Aggregated Data. Don't worry about the fact that it's talking about aggregated data (you can use whatever type of data that you want), or that it's geared towards presenting that data in a chart. There's many *useful* techniques in that article, & it shows just how easy it is to create your own custom RIA service.


    Yann

    (plus ça change, plus c'est la même chose!)

    Monday, July 4, 2011 11:40 PM

All replies

  • I noticed that as well. I am sure there is a good reason, but not sure what it is.
    Monday, July 4, 2011 5:28 PM
  • Monday, July 4, 2011 6:40 PM
  • Hi

    The answer was given by Eric Erhardt in:

    Join In PreprocessQuery

     

    Jaime

    Monday, July 4, 2011 7:18 PM
  • Holger,

    The PreProcessQuery method is fairly restricted in what you can do in it.

    For example you can can ONLY filter the records that are in the query parameter (which I see is what you're *trying* to do).

    You can't "add" records etc (& I know you're not trying to do that, I only mention it for completeness).

    The article that Jaime provided a link for is "joining" only in the sense that it's using related entities (navigation properties).

    Even though you're using a .ToList to attempt to "force" materialisation of your idsIncluded collection, that doesn't seem to be enabled in PreProcessQuery, so your collection will always be empty.

    Unless you can rethink your logic, to use only the entities in the query, or any of their related properties, you won't be able to do what you're trying to do in PreProcessQuery.

    You may need to invest a little time in a custom RIA service, assuming that you have VS Pro, or higher, not just stand-alone LS.

    If you need some background, or think it's "too difficult", have a look at How Do I: Display a Chart Built On Aggregated Data. Don't worry about the fact that it's talking about aggregated data (you can use whatever type of data that you want), or that it's geared towards presenting that data in a chart. There's many *useful* techniques in that article, & it shows just how easy it is to create your own custom RIA service.


    Yann

    (plus ça change, plus c'est la même chose!)

    Monday, July 4, 2011 11:40 PM
  • Thanks!
    Tuesday, July 5, 2011 8:20 AM
  • You're welcome!

    Yann

    (plus ça change, plus c'est la même chose!)

    Tuesday, July 5, 2011 10:14 AM
  • Hi Holger

    Sorry one question, could you indicate what the data model?

    Jaime

    Thursday, July 7, 2011 2:45 PM