Solving another error related to Entity Data Framework…

It is frustrating if even after you have done unit testing to your program, there will be always another type of error when you try to execute it in real environment. After testing for around 2 weeks, I still deal with type of error which is probably first time to me. This morning when I created new console application in Visual C#, I encountered error stated An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

It turned out that this error related to adding new record using Entity Data Framework. I actually have known how to add new instance into EDF before around 1 year ago. It just happened that after that, I never touched this thing since my last company only used .NET 2.0 for their website.

It took me quite a while before I realized the source of the error in the code below:

Adding EDF instance into DB

The commented part is the cause of the error and after I replaced with the line below it, the error is solved immediately. Simply put, The error was happened because I obtained personnels variable using different instance of EDF entity (not CJDBEnt which is used in above function) and apparently Visual Studio would not allow me to use multiple instances to be used during insertion of new record into database.

After I change it and getting personnels from the same instance (CJDBEnt), I have no more error.

 

Advertisements

About edwin2026

I am currently Indonesian expatriate working in Singapore, graduated from Nanyang Technological University with major in Computer Science in 2009. I am also working as software engineer, developing and maintaining systems for Singapore civil service. I write this blog to share to readers about my life principle on various aspects, like religion, politics, business, relationship, and technology. I am interested in alternative worldviews because I found that many things taught to us by establishments are not true and harmful. My dream is to become self-sufficient in food and energy. Hopefully, someday I can have my own fruit garden and my own power plant and able to sell my electricity to power company. I hope readers enjoy my blog.
This entry was posted in Work and tagged , , , . Bookmark the permalink.

One Response to Solving another error related to Entity Data Framework…

  1. ngalia says:

    Reblogged this on ngalia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s