I\'ve googled this and don\'t get any answers for my particular circumstance.
I could repro your issue. Your MemberProduct
has two Id
properties with different casing:
public class MemberProduct
{
public int Id { get; set; }
public int ID { get; set; }
}
EF code first uses conventions during the mapping. One of the convention is that it treats properties named Id
or TypenameId
as primary keys (if you don't use the Key
attribute or custom mapping) and because it does the property name comparison case insensitively it throws the exception.
Remove one of properties and it should work.
I got this sequence error when setting Entity state info incorrectly when initially seeding. Just make sure you're setting the state of object graphs correctly. My issue was with seeding data (not during the actual application run)...here's my answer anyway if it will help anyone if they're getting a sequence error (like "Sequence contains more than one matching element") when running the update-database command for migrations. While you're getting this error outside the seed method, I think your answer might lay in the Entity states for object graphs being set correctly.
Entity Framework Code First AddOrUpdate method insert Duplicate values
To get help with setting Entity object graphs correctly, see the following blog post which is the best I've found on correctly setting object state:
http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework-in-mvc/
In case it is of any use to anybody:
I received this error when populating a model using EF from a stored procedure. The stored procedure returned multiple columns, two of which had the same alias/name.
I suspect EF is getting confused by the two ID properties.
Change your private properties to fields; that should fix it.