Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:41:46+00:00 2026-05-22T18:41:46+00:00

I know that Entity Framework has some LINQ support problems (at least in comparison

  • 0

I know that Entity Framework has some LINQ support problems (at least in comparison to its predecessor LINQ to SQL)…and usually I’m able to find a creative way of restructuring my LINQ query so that it’s supported by EF and doesn’t throw a

"Unable to create a constant value of type ..."

But this time I’m having trouble. As usual, the problem is related to complex joins. This time it’s required for modeling some legacy data I’m working with.

I have a query for Offices (a simple POCO)

public IQueryable<Office> Offices
{
    get
    {
        IQueryable<Office> query = 
            from pn in _context.Locations
            where pn.Type == "Y"
            select new Office
            {
                Id = pn.Id  + 1000,
                Name = pn.Name,
            };

        query = query.Union(
            from r in _context.Resources
            where r.ResourceType == "L"
            select new Office
            {
                Id = r.ResourceId,
                Name = r.ResourceName,
            });

        return query;
    }
}

Then I have something else that has an Office property on it.

public IQueryable<ScheduleEntry> ScheduleEntries
{
    get
    {
        return 
            from pc in _context.CalendarEntries
            join o in this.Offices on pc.LocationId 
                equals o.Id into offices
            from office in offices.DefaultIfEmpty()
            let mainOffice = this.Offices.First()
            select new ScheduleEntry
            {
                Id = pc.CalendarId,
                StartDateTime = pc.StartDateTime ?? DateTime.MinValue,
                EndDateTime = pc.EndDateTime ?? DateTime.MinValue,
                Office = pc.LocationId == 0 ? mainOffice : office,
            };
    }
}

Please note, telling me to make it an enumerable defeats the purpose…so please don’t advise that.

And so….doing CalendarEntries.ToArray() throws "Unable to create a constant value of type Office"...

Specifically the problem is the let mainOffice = Offices.First(). If I remove that logic, the query works fine. Any idea how to make this work with Entity Framework?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:41:47+00:00Added an answer on May 22, 2026 at 6:41 pm

    Yep ok, looks like the double queryable is tripping it up. Only option is to either left join to Offices or do the following:

           Office mainOffice = Offices.First();
           return from pc in _context.CalendarEntries
                   join o in Offices on pc.LocationId equals o.Id into offices
                   from office in offices.DefaultIfEmpty()
                   select new ScheduleEntry
                              {
                                  Id = pc.CalendarId,
                                  StartDateTime = pc.StartDateTime ?? DateTime.MinValue,
                                  EndDateTime = pc.EndDateTime ?? DateTime.MinValue,
                                  Office = pc.LocationId == 0 ? mainOffice : office,
                              };
    

    I’m assuming you didn’t want to do that due to complaints about making it IEnumerable so you will need to join to the Offices queryable some how to tell EF how to string the queries together. Let x = y or value = value is looking for a constant which i guess makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Entity Framework to access my SQL data. I have some constraints in
I'm using the Play! framework and I have a model (an Entity) that has
I know that I can do something like $int = (int)99; //(int) has a
Does Visual Studio 2008 SP1 / .NET 3.5 support Linq to Entities (ADO.NET Entity
I'm having problems querying the entity model to get additional information. My db has
I'm trying to understand some fundamental best practices using Entity Framework. My EDM design
I am just learning the Entity Framework and have made some good progress on
I am using the POCO support for entity framework v4. I would like to
We are using entity framework 4 to access our database. Every table has got
I recently started using Entity Framework, and it has been kind of a pain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.