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

  • Home
  • SEARCH
  • 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 3807902
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:03:51+00:00 2026-05-19T15:03:51+00:00

I have a default Entity Framework model that holds all of my default tables

  • 0

I have a default Entity Framework model that holds all of my default tables for my product, and that all customers share in common. However, on some customers, I have some custom tables that exist for only that customer, but they relate to the default product’s tables. I have a second Entity Framework model to hold these custom tables.
My question is how can I make a Linq to Entities query using Join so I can relate the entities from my default model to the tables on my custom model? I don’t mind not having the Navigation properties from the custom entity to the entities on the default model; I just need a way to query both models in a single query.
Below is the code:

  using (ProductEntities oProductDB = new ProductEntities())
  {
    using (ProductEntitiesCustom oProductCustomDB = new ProductEntitiesCustom())
    {
      var oConsulta = oProductCustomDB.CTBLCustoms
                .Where(CTBLCustoms => CTBLCustoms.IDWOHD >= 12)
                .Join(oProductDB.TBLResources,
                     CTBLCustoms => new
                       {
                         CTBLCustoms.IDResource
                       },
                     TBLResources => new
                       {
                         TBLResources.IDResource
                       },
                    (CTBLCustoms, TBLResources) => new
                       {
                         IDCustom = CTBLCustoms.IDCustom,
                         Descricao = CTBLCustoms.Descricao,
                         IDWOHD = CTBLCustoms.IDWOHD,
                         IDResource = CTBLCustoms.IDResource,
                         ResourceCode = TBLResources.Code
                       });

      gvwDados.DataSource = oConsulta;
    }
  }

I get a The specified LINQ expression contains references to queries that are associated with different contexts error.
EDIT
Could I merge the 2 ObjectContext into a third, and then run the Linq query?
Tks

EDIT

Below is the code that worked, using the AsEnumerable() proposed solution:

  using (ProductEntities oProductDB = new ProductEntities())
  {
    using (ProductEntitiesCustom oProductCustomDB = new ProductEntitiesCustom())
    {
      var oConsulta = (oProductCustomDB.CTBLCustoms.AsEnumerable()
                .Where(CTBLCustoms => CTBLCustoms.IDWOHD >= 12)
                .Join(oProductDB.TBLResources,
                     CTBLCustoms => new
                       {
                         CTBLCustoms.IDResource
                       },
                     TBLResources => new
                       {
                         TBLResources.IDResource
                       },
                    (CTBLCustoms, TBLResources) => new
                       {
                         IDCustom = CTBLCustoms.IDCustom,
                         Descricao = CTBLCustoms.Descricao,
                         IDWOHD = CTBLCustoms.IDWOHD,
                         IDResource = CTBLCustoms.IDResource,
                         ResourceCode = TBLResources.Code
                       })).ToList();

      gvwDados.DataSource = oConsulta;
    }
  }

I added the AsEnumerable() as suggested, but I had to add the ToList() at the end so I could databind it to the DataGridView.

  • 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-19T15:03:52+00:00Added an answer on May 19, 2026 at 3:03 pm

    You can’t do this in L2E. You could bring this into object space with AsEnumerable(), and it would work, but possibly be inefficient.

    Merging the ObjectContexts is possible, and would work, but would need to be done manually.

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

Sidebar

Related Questions

We have a simple Table per Type Entity Framework 4.0 model :- ALl classes
I have created a Entity Framework 4 model with Visual Studio 2010 and generated
Using the Entity Framework that I generated. I have a Roles table created during
I have two Sql Server tables accessed through Entity Framework 4. They are joined
My server have default php version of 4, so when I run some script
I have some default values for testing my code, but for security reasons those
I have a default ListView that i have added my custom views for the
I have a default a:hover styling however for certain things I have written a
I have a little app that have by default youtube as homepage. You can
I am trying to create an Entity Framework 4 model based on a legacy

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.