Note that there are some explanatory texts on larger screens.

plurals
  1. POEF4 Code First CTP5: Seed method no longer works
    primarykey
    data
    text
    <p>I had EF Code First CTP4 working fine, and I installed CTP5 today. Now, I get an exception when my database is repopulated.</p> <p>Here is my model:</p> <pre><code>public class Member { public Member() { DateCreated = DateTime.Now; DateUpdated = DateTime.Now; DateLastLogin = DateTime.Now; } [Key, DatabaseGenerated(DatabaseGenerationOption.Identity)] \\I have tried removing these annotations and the result is the same public int MemberId { get; set; } [Required,RegularExpression(".+\\@.+\\..+", ErrorMessage = "Please enter a valid email address")] public string Email { get; set; } [Required,StringLength(20,MinimumLength=2)] public string FirstName { get; set; } [Required, StringLength(20, MinimumLength = 2)] public string LastName { get; set; } [Required, StringLength(36, MinimumLength = 2)] public string City { get; set; } [Required, StringLength(20, MinimumLength = 2)] public string State { get; set; } [Required, StringLength(20, MinimumLength = 2)] public string Zip { get; set; } public double GeoLat { get; set; } public double GeoLong { get; set; } public string AccountStatus { get; set; } public DateTime DateCreated { get; private set; } public DateTime DateUpdated { get; set; } public DateTime DateLastLogin { get; set; } public virtual PublicProfile Profile { get; set; } } </code></pre> <p>Here is the code that is being called in Global.asax.cs</p> <pre><code>protected void Application_Start() { RegisterRoutes(RouteTable.Routes); DbDatabase.DefaultConnectionFactory = new SqlConnectionFactory("System.Data.SqlClient"); DbDatabase.SetInitializer&lt;MeetPplDB&gt;(new Initializer()); } public class Initializer : DropCreateDatabaseAlways&lt;MeetPplDB&gt; { protected override void Seed(MeetPplDB context) { var Members = new List&lt;Member&gt; { new Member { Email = "dave@dave.com", City = "San Francisco", AccountStatus = "Active", State = "CA", FirstName = "David", LastName = "Daverson", Zip = "94118", GeoLat = 37.735, GeoLong = -122.392 }, new Member { Email = "bob@bob.com", City = "Oakland", AccountStatus = "Active", State = "CA", FirstName = "Bob", LastName = "Boberson", Zip = "94601", GeoLat = 37.781, GeoLong = -122.216 }, new Member { Email = "jenny@jenny.com", City = "San Francisco", AccountStatus = "Active", State = "CA", FirstName = "Jenny", LastName = "Jennerson", Zip = "94123", GeoLat = 37.735, GeoLong = -122.392 } }; Members.ForEach(m =&gt; context.Members.Add(m)); context.SaveChanges(); } } </code></pre> <p>When it hits the SaveChanges on the context, I get this exception:</p> <blockquote> <p>Conflicting changes detected. This may happen when trying to insert multiple entities with the same key.</p> <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p> <p>Exception Details: System.Data.UpdateException: Conflicting changes detected. This may happen when trying to insert multiple entities with the same key.</p> </blockquote> <p>Does anyone have any idea what has changed and why this does not work any more? What needs to change for this to work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload