Miałem kod EF Najpierw CTP4 działa dobrze, a ja zainstalowałem dzisiaj CTP5. Teraz otrzymuję wyjątek, gdy moja baza danych zostanie ponownie zaludniona.Kod EF4 Najpierw CTP5: Metoda nasion już nie działa
Oto mój model:
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; }
}
Oto kod, który jest nazywany w 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 = "[email protected]",
City = "San Francisco",
AccountStatus = "Active",
State = "CA",
FirstName = "David",
LastName = "Daverson",
Zip = "94118",
GeoLat = 37.735,
GeoLong = -122.392 },
new Member {
Email = "[email protected]",
City = "Oakland",
AccountStatus = "Active",
State = "CA",
FirstName = "Bob",
LastName = "Boberson",
Zip = "94601",
GeoLat = 37.781,
GeoLong = -122.216 },
new Member {
Email = "[email protected]",
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();
}
}
Kiedy trafi na SaveChanges od kontekstu, otrzymuję ten wyjątek :
Wykryto występujące konflikty. Może się to zdarzyć podczas próby wstawienia wielu elementów za pomocą tego samego klucza.
Opis: Wystąpił nieobsługiwany wyjątek podczas wykonywania bieżącego żądania WWW. Sprawdź ślad stosu, aby uzyskać więcej informacji o błędzie i skąd pochodzi w kodzie.
Szczegóły wyjątku: System.Data.UpdateException: Wykryto występujące konflikty. Może się to zdarzyć podczas próby wstawienia wielu elementów za pomocą tego samego klucza.
Czy ktoś ma pojęcie, co się zmieniło i dlaczego to nie działa? Co trzeba zmienić, aby to zadziałało?
nie widzę niczego złego w kodzie lub odtworzyć problem. Przepraszam, powodzenia. – Paul
Obserwuję [tę serię] (http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction- i-model.aspx) na CTP5, a mój inicjator nie ma żadnych wywołań "SaveChanges", ale nadal poprawnie wypełnia bazę danych. Może zmieniło się coś pomiędzy CTP4 i CTP5, jeśli chodzi o miejsca zapisywania zmian dla inicjalizatora? – ProfK