2012-03-19 5 views
1

まずプロジェクトをビルドするためにEFコードを使用しています。 シードメソッドを使用してデータベース内のデータを初期化しますが、一部のクラスモデルデータのみがデータベースに登録されています。 私は警告や問題はありません。 exempleため :EF 4.1コードファースト私のデータベースを初期化する

public class Categorie 
    { 
     public int CategorieID { get; set; } 
     public string Nom { get; set; } 
     public virtual ICollection<Cour> Cours { get; set; } 
    } 

2)

var coachs = new List<Coach> 
      { 
new Coach{Nom="Guith",Prenom="Etienne", Login="etienneguith",Password="etienneguith",Profession="Neurologue",Cour="Medecine generale",Email="[email protected]",agenda=temp1}, 
new Coach{Nom="John",Prenom="Robert", Login="robertjohn",Password="robertjohn",Profession="Juge",Cour="Droit Penal",Email="[email protected]",agenda=temp2}, 
}; 
     categories.ForEach(s => context.Categories.Add(s)); 
     context.SaveChanges(); 

クラスモデル

public class Coach 
    { 
     public int CoachID { get; set; } 
     public string Nom { get; set; } 
     public string Prenom { get; set; } 
     public string Login { get; set; } 
     public string Password { get; set; } 
     public string Profession { get; set; } 
     public string Cour { get; set; } 
     public string Email { get; set; } 
     public DateTime agenda { get; set; } 


     public virtual ICollection<Session> Sessions { get; set; } 

    } 
+0

は、データベースに書き込まれ得ていない 'Coach'コレクションですか? –

+0

シードを実行するコードを共有できますか? –

+0

このコードは 'IDatabaseInitializer'実装の' Seed() 'メソッドから来たものとします。残りの実装と、データベース初期化子を設定するコードを投稿できますか? –

答えて

3

を完了あなたがunintいるように見える: 1)がない

var categories = new List<Categorie>{ 
       new Categorie{Nom="Informatique"}, 
       new Categorie{Nom="Bien Etre"}, 
}; 
      categories.ForEach(s => context.Categories.Add(s)); 
      context.SaveChanges(); 

クラスモデルをい扇動的にカテゴリのコレクションを2回繰り返します。

var coachs = new List<Coach> 
{ 
    new Coach{Nom="Guith",Prenom="Etienne", Login="etienneguith",Password="etienneguith",Profession="Neurologue",Cour="Medecine generale",Email="[email protected]",agenda=temp1}, 
    new Coach{Nom="John",Prenom="Robert", Login="robertjohn",Password="robertjohn",Profession="Juge",Cour="Droit Penal",Email="[email protected]",agenda=temp2}, 
}; 

categories.ForEach(s => context.Categories.Add(s)); 
context.SaveChanges(); 

それがあるべきように見える:

var coachs = new List<Coach> 
{ 
    new Coach{Nom="Guith",Prenom="Etienne", Login="etienneguith",Password="etienneguith",Profession="Neurologue",Cour="Medecine generale",Email="[email protected]",agenda=temp1}, 
    new Coach{Nom="John",Prenom="Robert", Login="robertjohn",Password="robertjohn",Profession="Juge",Cour="Droit Penal",Email="[email protected]",agenda=temp2}, 
}; 

coachs.ForEach(s => context.Coachs.Add(s)); 
context.SaveChanges(); 
+0

申し訳ありませんが、私は自分の質問を投稿するときに唯一の間違いです、私は同じコードを貼り付けます。私のプロジェクトでそれはあなたの変更のようにnormalyですが、 – user1235486

関連する問題