delete data using entity framework
Posted
by
user3474542
on Stack Overflow
See other posts from Stack Overflow
or by user3474542
Published on 2014-06-06T15:22:30Z
Indexed on
2014/06/06
15:24 UTC
Read the original article
Hit count: 187
The objective of the method below is to delete the data from the database using entity framework. I am populating the subscriptions entity by passing two parameters and then calling the atttach and remove method of the context class. Bureau entities is the context class.
using (BUREAUEntities bureauEntities = new BUREAUEntities()) {
var subscription = new SubcriptionRepository().GetSusbcriptionBySubscriptionTypeId(subscriptionTypeId, companyId);
bureauEntities.Subscriptions.Attach((DataAccessLayer.DatabaseModel.Subscription)subscription);
bureauEntities.Subscriptions.Remove(subscription);
bureauEntities.SaveChanges();
}
I am getting the following error message at An entity object cannot be referenced by multiple instances of IEntityChangeTracker at line
bureauEntities.Subscriptions.Attach((DataAccessLayer.DatabaseModel.Subscription)subscription);
Could somebody tell me where am I going wrong ?
© Stack Overflow or respective owner