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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:12:55+00:00 2026-05-26T00:12:55+00:00

I have three tables Job, Contact and a reference table between them named JobContact.

  • 0

I have three tables Job, Contact and a reference table between them named JobContact. When I delete a record from JobContact table, so record is deleted from database, but it is still present in code. I mean, when I do a select Job by key and when I’m accessing job.JobContact, so record is still there.

How can I force EF to get the current data from this table?

Edited:

I’m using EF to delete the record. Here is a code sample how I’m doing it:

Step 1: delete record from JobContact:

var jobContactRepos = RepositoryFactory.GetRepository<JobContact>();    
var jobContact = jobContactRepos.SelectByKey(jobContactId);

jobContactRepos.Delete(jobContact);
jobContactRepos.Save(); 

Step 2: get the job record from DB after step 1 is done:

var jobRepos = RepositoryFactory.GetRepository<Job>();
var job = jobRepos.SelectByKey(id);

After Step 1, record is deleted from DB: it is OK.

After Step 2, record is still present in the job.JobContact entity: it is not OK.

RepositoryFactory creates already a new context. So I don’t understant. In which place in my code should I use Refresh() method?

thanks

  • 1 1 Answer
  • 1 View
  • 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-26T00:12:56+00:00Added an answer on May 26, 2026 at 12:12 am

    You can dispose your EF context and create a new one, this will force EF to get fresh data from the DB instead of using possibly cached data. Alternatively you can call Refresh() on your context using RefreshMode.StoreWins.

    But the real question is why do you delete this record from the database directly and don’t use EF for it? Had you used the EF context to remove the Contact entity from the Contacts navigation property collection of your Job entity, this problem shouldn’t be there in the first place.

    Edit:

    The reference table should be represented in EF as a navigation property Contacts in your Job entities, and a navigation property Jobs in your Contact entities. Are you using an older version of EF (I am probably not familiar enough with previous versions) or have a custom repository layer that introduces this reference entity?

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

Sidebar

Related Questions

I have three tables such as user, job and job_applied. user table has uid
I have three tables that have the following relationships between them: Account { public
I have three tables that contain data relating to a Job. One table is
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have a Job table and a Contact table, I need to create another
I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three tables of information where the business_id is the common thread. I
I have three tables being used for this problem: songs, blacklist, and whitelist. The
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body

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.