Troelsen book – little problem with EntityFramework and Seed method

Hello! I am learning C# and .net core from troelsen book, but I have troubles with Seed method in EntityFramework chapter (23).

Going to the point, when the database is clear update-database run smoothly, but with the little catch – line 45-51 of that code:

rather than use already added Cars and Customers choose to add a new, so there will be duplicates in databse. So the consequences is that the next update-databse throw an exception

Sequence contains more than one element. 

Anybody know where’s the problem and how to correct that? Even the official(?) git of that book have the same problem, so you can duplicate that code and try it yourself.

submitted by /u/ifinox
[link] [comments]

Leave a Reply