EF 4.0 IsAttachedTo extension method and error An object with the same key already exists
问题 I was getting an error An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key. After i googled it i found IsAttachedTo extension method there: Is is possible to check if an object is already attached to a data context in Entity Framework? here is my code: foreach (string s in types) { Subscription subscription = new Subscription { Id = Int32.Parse(s) }; if (service.repository._context.IsAttachedTo