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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:45:06+00:00 2026-06-16T04:45:06+00:00

can’t find any matching solution. Let’s head to the point: MVC4 application, EF and

  • 0

can’t find any matching solution.
Let’s head to the point: MVC4 application, EF and CodeFirstSharpMembership provider.

There is an entity

 public class User
{
    ...
    public virtual ICollection<Role> Roles { get; set; }
}

And standard Role Entity:

public class Role
{
    ...
    public virtual ICollection<User> Users { get; set; }
}

And of course when I try to make my own Entity with FK to User

public class MyEntity
{
    ...
    public virtual User Developer { get; set; }
}

I always get Self-Referrence loop because User reffers to Roles, and Roles reffers to User.

Then I tryed to

Context = new DataContext();
Context.Configuration.LazyLoadingEnabled = false;

To avoid selecting any Foreign Keys, and after selecting something

var Developers = Context.MyEntities;

And of course my IQueryable was without “Developer” field.

Then I tryed to:

var Developers = Context.MyEntities.Include("Developer");

And of course got Self-Referrence loop.

How can I keep selecting FKeys and exclude “Role” field from User?

  • 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-16T04:45:07+00:00Added an answer on June 16, 2026 at 4:45 am

    There shouldn’t be a problem with self-referencing entities unless you are using a method that cannot handle the self-referencing (like serialization). If you are having serialization problems (I have to guess because you haven’t provided any what you are trying to produce the error message, most likely serialization or data binding I simply don’t know) so I would suggest:

    Turning off Proxy object creation on your DbContext.

    DbContext.Configuration.ProxyCreationEnabled = false;
    

    Typically this scenario is because the application is using POCO objects (Either T4 Generated or Code-First). The problem arises when Entity Framework wants to track changes in your object which is not built into POCO objects. To resolve this, EF creates proxy objects which lack the attributes in the POCO objects, and aren’t serializable.

    I’d also add that you have an XY Problem. You are asking how to exclude a property(The Y Problem) because you think it will solve a problem (The X Problem) and it may or it may not. In actuality you need to state source problem (X) because there will be most likely a solution (like i’ve described) that doesn’t require (Y) at all.

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

Sidebar

Related Questions

Can anyone let me know how can we change the value of kendo combobox
Can any one tell, how to get the result of LINQ query contains group
Can anybody tell me a regular expression to use within some PHP to find
Can some one confirm me that only one UIWindow instance is possible in any
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can anyone tell me how an IDE like NetBeans or any for that matter
Can a desktop .net library [Aforge.net] be used in a .Net CF 3.5 application?
Can not find scala.actors package in latest milestones, while it still presents in scaladocs:
Can find why i get this error can someone help? package Android.data; public class
Can anyone help me trying to find out why this doesn't work. The brushes

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.