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 8532001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:48+00:00 2026-06-11T09:36:48+00:00

I have some POCO classes which can generally divided into two groups, for example:

  • 0

I have some POCO classes which can generally divided into two groups, for example:

public class Student
{
    public Student()
    {
        this.Courses = new List<Course>();
        this.Clubs = new List<Club>();
    }

    public int Id { get; set; }
    public virtual ICollection<Course> Courses { get; set; }
    public virtual ICollection<Club> Clubs { get; set; }
}

and corresponding Course and Club classes, and they all have their own relationships to other classes.

The problem is, those two groups are big, they both contains a lot of classes, and each of them is a working unit, like student courses management unit which will provide functions for anything related to course; and club management unit which will provide functions. So I am not planning to put them together into one DbContext.

There are some requirements that will need to get a student from club then retrieve its course information. What I am doing now, is do another query in course unit by using the student Id I got from club unit. Which works fine but I hopping to make it simpler, like

foreach(var student in club.Students){
    ClubContext.Detach(student);
    CourseContext.Attach(student);
    foreach(var c in student.Courses){
      ...
    }
}

but I got some exception like this:

There is already a generated proxy type for the object layer type
‘POCOTest.Models.Student’. This occurs when the same object layer
type is mapped by two or more different models in an AppDomain.

Is this possible? and if so, how? 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-06-11T09:36:49+00:00Added an answer on June 11, 2026 at 9:36 am

    You can have single class mapped in multiple contexts but the mapping should be always the same. If it is not the same you cannot use dynamic proxies (lazy loading) because each mapping demands its own proxy type handling its navigation properties.

    In your case the first context mapping contains Student entity with relation to Club but this relation doesn’t exist in the second mapping where in contrary relation with Course exists. That demands two different proxy types for the same entity type.

    The exception says that it is not supported. There are two reasons why this cannot work:

    • EF stores proxy types in static dictionary where each entity type can have only single generated proxy
    • Even if you fix the first point (by downloading source codes and modifying them) you will still not be able to do what you want because proxy type is the entity. It is not a wrapper. So the type cannot be replaced when you detach it from the first context and attach to second one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some POCO objects that look something like this: public class Foo {
I have the following Entity Framework POCO classes: public class Customer { public int
I'm testing with EF 4.3 (beta) I have some new classes which should generate
I have read some articles on POCO in the enttity framework but still don't
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
Can anyone tell me if its possible to extract the linq2sql generated classes into
I'm mapping some POCO classes to an existing database with several lookup tables and
I have some POCO objects that are set up for use with Entity Framework
I have an EDMX file with context.tt and .tt file. I have POCO classes
I have some logic whereby a graph of POCO entities need to be cloned

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.