gpt4 book ai didi

c# - EF4 代码优先 CTP5 : Seed method no longer works

转载 作者:太空狗 更新时间:2023-10-29 23:53:05 24 4
gpt4 key购买 nike

<分区>

我的 EF Code First CTP4 运行良好,今天我安装了 CTP5。现在,当我的数据库重新填充时出现异常。

这是我的模型:

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; }
}

这是在 Global.asax.cs 中调用的代码

protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
DbDatabase.DefaultConnectionFactory = new SqlConnectionFactory("System.Data.SqlClient");
DbDatabase.SetInitializer<MeetPplDB>(new Initializer());
}

public class Initializer : DropCreateDatabaseAlways<MeetPplDB>
{
protected override void Seed(MeetPplDB context)
{
var Members = new List<Member>
{
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 => context.Members.Add(m));
context.SaveChanges();
}
}

当它命中上下文中的 SaveChanges 时,我得到这个异常:

Conflicting changes detected. This may happen when trying to insert multiple entities with the same key.

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.

Exception Details: System.Data.UpdateException: Conflicting changes detected. This may happen when trying to insert multiple entities with the same key.

有谁知道发生了什么变化以及为什么这不再起作用?需要更改什么才能使其生效?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com