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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:12:59+00:00 2026-05-28T04:12:59+00:00

I think i ran into a bug, it seems that EF is not handling

  • 0

I think i ran into a bug, it seems that EF is not handling references well after deleting and reinserting an entity. I’ve managed to reproduce it with the code below (assume all asserts pass except the one i talk about in the comments):

var database = new TestEntities();

// select and delete the info record
var info = database.Info.First(i => i.ID == 1);
Assert.AreEqual(1, info.MemberID);
// when i uncomment the line below the last Assert fails
// Assert.IsNotNull(info.Member);
database.Info.Remove(info);

// add it again and persist it to the database
database.Info.Add(new Info {
    ID = 1,
    MemberID = 1
});
database.SaveChanges();

// should not be null ? EDIT: i guess i understand this becoming null
Assert.IsNull(info.Member);

// and even here its still null
info = database.Info.First(i => i.ID == 1);
Assert.IsNull(info.Member);

Can anyone tell me whats going on here?

EDIT:
My entities are generated using database first and im using the DbContext/POCO generator.

public partial class Member
{
    public Member()
    {
        this.Info = new HashSet<Info>();
    }

    public int ID { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Info> Info { get; set; }
}

public partial class Info
{
    public int ID { get; set; }
    public int MemberID { get; set; }

    public virtual Member Member { get; set; }
}
  • 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-28T04:13:00+00:00Added an answer on May 28, 2026 at 4:13 am

    It turns out that it had nothing to do with deleting and reinserting, not really anyway. It was was so obvious …

    I was inserting using a POCO which is not eagerly loaded and does not have any lazy loading capabilities …

    The second time i queried for the same record i was expecting a proxy, but it seems that the POCO was cached by EF and that is what it returned meaning still no eager or lazy loading.

    I can fix it by making sure EF doesn’t retrieve the second query from cache, inserting using a proxy (var info = database.Info.Create()) or including member in the query (database.Info.Include(i => i.Member).First(i => i == 1)).

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

Sidebar

Related Questions

We ran into a bug in our product caused by the fact that for
I ran into a bug I have trouble explaining. Now that I found the
I ran into this today and the only thing I can think is that
I'm new to anonymous classes, and today I think I ran into the first
Possible Duplicate: Reversing a regular expression in python I think I ran into a
A co-worker ran into an interesting issue today, and while I think the actual,
I ran into the situation that I need a way to edit the data
Just ran into a bit of code that wasn't doing what I thought it
I think the title is pretty clear. I have ran into this twice now.
I ran into a bug in a mime parsing library where it blows up

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.