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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:04:00+00:00 2026-06-04T06:04:00+00:00

I have a complex object which has references to other objects, I am trying

  • 0

I have a complex object which has references to other objects, I am trying to save it from my web application.

so, in my webapplication, I call the business logic, and from the bl, I call the DAL Facade, and then the DAL.

When I execute the Insert method I am having the exception.

Code in the DAL layer, this is where the exception is raised.

public void InsertEcoBonusRequest(EcoBonusRequest ecoBonusRequest)
        {
            _context.EcoBonusRequests.Add(ecoBonusRequest);
        }

Code in the Unitofwork.cs

public void Save()
        {
            _context.SaveChanges();
        }

 private RequestBaseRepository _requestBaseRepository;

 public EcoBonusRequestRepository EcoBonusRequestRepository
            {
                get
                {
                    return _ecobonusworkflowRepository ??
                            (_ecobonusworkflowRepository = new EcoBonusRequestRepository(_context));
                }
            }

Code in the dal facade:

private  static readonly UnitOfWork UnitOfWork = new UnitOfWork();

        public void Save(EcoBonusRequest ecoBonusRequest)
        {
            UnitOfWork.EcoBonusRequestRepository.InsertEcoBonusRequest(ecoBonusRequest);
        }

Code in the BL

public void Save(EcoBonusRequest ecoBonusRequest)
        {
            EcoBonusRequestFacade.Save(ecoBonusRequest);

}


**Code in the page.aspx.cs, as you can see the element ecobonusworkflow is neverstored in the database, but the navigation entities are stored already.**

 var dealer = DealerBL.GetDealer(Nuteres);
  var requester = RequesterBL.GetRequester(int.Parse(DdlRequester.SelectedItem.Value));
                var selectedVehicle = VehicleBL.GetVehicle(VehicleInformationControl.Chassis);


var ecoBonusWorkflow = new EcoBonusRequest
                {
                    IsOnHold = true,
                    AmmountWithoutVAT = decimal.Parse(TxtVatExcluded.Text),
                    AmmountWithVAT = decimal.Parse(TxtVatIncluded.Text),
                    BrandReturnedVehicle = TxtBrandReturnedVehicle.Text,
                    ChassisReturnedVehicle = TxtChasisReturnedVehicle.Text,
                    Percentage = (decimal.Parse(TxtVatExcluded.Text)/VehicleInformationControl.InvoicedAmmount)*100,
                    Comments = TxtComments.Text,
                    Customer = new Customer
                    {
                        FirstName = TxtFirstName.Text,
                        LastName = TxtLastName.Text,
                        Address = new Address
                        {
                            Street = TxtStreet.Text,
                            Number = TxtNumber.Text,
                            Box = TxtBox.Text,
                            City = TxtCity.Text,
                            Zip = TxtZip.Text
                        }
                    },
                    CurrentStatus = "Approval1",
                    Dealer = dealer,
                    Requester = requester,
                    VehicleDesctructionDate = DateTime.Parse(TxtVehicleDestructionDateReturnedVehicle.Text, userCulture),
                    DestructionCertificateNumberReturnedVehicle = TxtDestructionCertificateNumberReturnedVehicle.Text,
                    TypeReturnedVehicle = TxtTypeReturnedVehicle.Text,
                    Vehicle = selectedVehicle
                };
                EcoBonusRequest = ecoBonusWorkflow;
                UploadFiles();
                RedirectToPage("~/Requests/confirmation.aspx");
  • 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-04T06:04:01+00:00Added an answer on June 4, 2026 at 6:04 am

    The exception states that your entity, or navigation entities of the root entity is already attached to another context.
    Depending on your architecture, you should either create a new context and attach it every time; or if you are reusing the context you should refresh the context with new values.

    In your case, it seems you are creating a new context, but a previous context has not been disposed thus the entity is still attached to the older context. In this case, just reuse the older context instead of creating a new one.

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

Sidebar

Related Questions

I have a complex django object, which has properties of other class types. This
I have a fairly complex object which has some C# code written to render
I have a complex network of objects being spawned from a sqlite database using
I have an complex object on my web server - lets say the object,
I have a complex object(tree structure) which I am flattening it out into a
I have a simple WCF service which has a method that returns a complex
I have a pretty complex object graph G with an object o1 in G
What is the format for databinding to a complex object? I have a linq
I have a method that return a complex JSON object. It's a heavy processing
In my model I have three complex scopes returning the Discount object arrays. Each

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.