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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:54:52+00:00 2026-06-16T00:54:52+00:00

Hi I am using a unit of work pattern on an EF4 context. The

  • 0

Hi I am using a unit of work pattern on an EF4 context.

The context is being passed across a few methods that all do work on it and then when done I calling save changes.

When I peform a check later on on the state of the object it is the old values not new. yet if i were to call save changes at that point the state I would expect to be seen on the context is saved to the database.

essentially the call stack would be

Context ctx;

UpdateItems(ctx);
CheckItemsValid(ctx);
DoSomehtingElse(ctx); //Saving changes here.

Now the CheckItemsValid is failing as it cant see the changes made in UpdateItems, yet it is the same context.

If I wrap the whole thing in a TransactionScope and call SaveChanges before calling check items everything works that seems a bit of a sledgehammer to crack a nut though.

I have tried the following after updating the items in the update items method.

ApplyCurrentValues();
Refresh(ClientWins);
AcceptAllChanges();

Has any one seen this issue before or do i have to just transact the whole thing and call saves changes mid flow?

    using (EntitiesContext ctx = EntityFactory.GetEntitiesContext())
        {

            Repairs.RepairManager repman = new Repairs.RepairManager();

            repman.SetAllRepairsOfTypeToComplete(vehicle.VehicleId, RepairTypes.BodyShop, vehicle.SiteVisitId.Value, technicianId, ctx);


            SchemeManager sm = new SchemeManager();
            result = sm.ProcessVehicle(AutoMapper.Mapper.Map<EFVehicle, AbstractVehicle>(ctx.EFVehicles.Single(p => p.VehicleID == vehicle.VehicleId), new Vehicle()), ref intrules, userId, ctx, false);


            if (result == true)
            {
                ctx.SaveChanges();         
            }

is the base of it the processvehicle call checks that SetAllRepairsOfTypeToComplete was successful

Set all repairs to complete simply updates an bit from true to false on the Repairs list that is on the context ctx.EFRepairs.

  var cancelledrepairs = ((EntitiesContext)Context).EFRepairs.Where(p => p.VehicleID == vehicle.VehicleId && p.VehicleSiteVisitID == vehicle.SiteVisitId
            && p.RepairTypeID == (int)RepairTypes.BodyShop && p.RepairStatusID == (int)RepairStatusEnum.Cancelled).Count();

        var completedMechrepairs = ((EntitiesContext)Context).EFRepairs.Where(p => p.VehicleID == vehicle.VehicleId && p.VehicleSiteVisitID == vehicle.SiteVisitId
            && p.RepairTypeID == (int)RepairTypes.BodyShop && p.RepairStatusID == (int)RepairStatusEnum.Completed).Count();

        var CurrentMechanicalRepairs = ((EntitiesContext)Context).EFRepairs.Where(p=> p.VehicleID == vehicle.VehicleId && p.VehicleSiteVisitID == vehicle.SiteVisitId
            && p.RepairTypeID == (int)RepairTypes.BodyShop).Count();

        if ((completedMechrepairs + cancelledrepairs) == CurrentMechanicalRepairs)
            return true;
        else
        {
            failureMessage = "Not all mechanical repairs for this vehicle are complete";
            return false;
        }

The completedMechrepairsCount is always 0 even though they were updated in SetAllRepairsOfTypeToComplete on the same context.

  • 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-16T00:54:54+00:00Added an answer on June 16, 2026 at 12:54 am

    This should work in principle. I even created a local test that mimics this behavior and it worked for me. I think that the most likely causes are: (any/all)

    1) Your SetAllRepairsOfTypeToComplete method isn’t updating the object(s) you think it is.

    -or-

    2) Your query to get the completedMechrepairs count isn’t picking up the correct object(s).

    Try doing some debugging where your EFRepair object has a unique ID that you can use to see if it gets updated. Then get a List back from your completedMechrepairs check and see if that EFRepair object with that ID is in the list.

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

Sidebar

Related Questions

I am using EF4.3 with a unit-of-work + repository pattern. I have a method
I'm using ravendb as storage backend. Since it uses unit of work pattern I
We are working using the Unit Of Work pattern combined with the Generic Repository
I am using EF with Repository Pattern and unit of Work. I am pulling
I'm using the Repository and Unit Of Work Pattern with Entity Framework 5 I
Currently in my application and using the unit of work pattern and generic repository,
I am using asp.net mvc and nhibernate with the unit of work pattern. I
I want to build a windosform application using Repository and Unit of Work pattern.
I'm using NHibernate, DI/IoC and the Unit of Work pattern. Most UoW examples I've
I'm using the Unit Of Work Pattern with my data layer. public interface IUnitOfWork{

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.