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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:21:05+00:00 2026-06-15T11:21:05+00:00

We are working using the Unit Of Work pattern combined with the Generic Repository

  • 0

We are working using the Unit Of Work pattern combined with the Generic Repository pattern.

Are POCO’s are built like this:

public class Aclass: IEntity{
public int ID;
public virtual Bclass Bproperty;
public virtual Cclass Cproperty;
}

With IEntity

public interface IEntity{
int ID;
} 

When we are creating an unique A-object, we are referring to an already existing B-object and C-object.
When we .SaveChanges() A is saved, but also a copy of B and C. So instead of referring to the original B and C objects, A’s Bproperty and Cproperty are referring to new objects.

We can fix it by attaching, but given the fact we are working with patterns, this screws with our level of abstraction.

Does anyone have a clue on how to fix this in a clean way?

  • 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-15T11:21:06+00:00Added an answer on June 15, 2026 at 11:21 am

    You have to mark the existing B and C objects as Unchanged before the SaveChanges

    context.Entry<BClass>(bclass).State = EntityState.Unchanged; 
    

    or

    context.ObjectStateManager.ChangeObjectState(AEntity.BClass, EntityState.Unchanged);
    

    (depending on what kind of context you’re using)

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

Sidebar

Related Questions

I'm working with webapi, MVC 4 project. (using repository pattern and Unit of Work)
At the moment I'm working on Asp.Net MVC using: Repository, Unit-Of-Work patterns, Service Layer
I'm using the Unit Of Work Pattern with my data layer. public interface IUnitOfWork{
This is a basic understanding concepts related question. Working using: Embarcadero C++ Builder What
I'm actually working on a Symfony project at work and we are using Lucene
I'm using Emacs and trying to get my unit testing work flow as automated
I am working on this WebAPI project and I need to create unit tests
I was working on a Unit of Work implementation that works both in Entity
I'm working using scriptaculous library. However I'm facing some issues with inclusion of the
I just started working using Google Maps API yesterday, and trying to set 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.