public class Initializer : DropCreateDatabaseAlways<MeetPplDB>
{
protected override void Seed(MeetPplDB context)
{
var Members = new List<Member>
{
new Member {
Email = "[email protected]",
City = "San Francisco",
.....
尝试这个
public class Initializer : DropCreateDatabaseAlways<MeetPplDB>
{
protected override void Seed(MeetPplDB context)
{
var _members = new List<Member>
{
new Member {
Email = "[email protected]",
City = "San Francisco",
....
_members.ForEach(m => context.Members.Add(m));
context.SaveChanges();
Maybe because your variable name that you using has been generated as pluralized by EF.
Instead of :
public class Initializer : DropCreateDatabaseAlways<MeetPplDB>
{
protected override void Seed(MeetPplDB context)
{
var Members = new List<Member>
{
new Member {
Email = "[email protected]",
City = "San Francisco",
.....
try this
public class Initializer : DropCreateDatabaseAlways<MeetPplDB>
{
protected override void Seed(MeetPplDB context)
{
var _members = new List<Member>
{
new Member {
Email = "[email protected]",
City = "San Francisco",
....
_members.ForEach(m => context.Members.Add(m));
context.SaveChanges();
异常的原因是您将数据类型 int 与 DatabaseGenerationOption.Identity 结合在一起。使用 Identity 将生成 guid 而不是 int key。
我有一个类似的问题,因为我想要一个 int 类型的 Key 和一个 Guid 作为唯一的 rowid。如果我在一个实体上使用两者,即使它们位于单独的道具中,种子也会停止工作。
The reason for your exception is that you have datatype int combined with DatabaseGenerationOption.Identity. Using identity will generate a guid and not a int key.
I have a similar problem because I want to have a Key of type int and a Guid as a unique rowid. And seed stops working if I use both on a entity even if they're in separate props.
发布评论
评论(2)
也许是因为您使用的变量名已由 EF 生成为复数形式。
而不是:
尝试这个
我将你的代码与 Scott Gu 的进行比较
http:// /weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
Maybe because your variable name that you using has been generated as pluralized by EF.
Instead of :
try this
I compare your code with Scott Gu's
http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
异常的原因是您将数据类型 int 与 DatabaseGenerationOption.Identity 结合在一起。使用 Identity 将生成 guid 而不是 int key。
我有一个类似的问题,因为我想要一个 int 类型的 Key 和一个 Guid 作为唯一的 rowid。如果我在一个实体上使用两者,即使它们位于单独的道具中,种子也会停止工作。
The reason for your exception is that you have datatype int combined with DatabaseGenerationOption.Identity. Using identity will generate a guid and not a int key.
I have a similar problem because I want to have a Key of type int and a Guid as a unique rowid. And seed stops working if I use both on a entity even if they're in separate props.