2017-08-03 9 views
0

私はEF 6.xを使用してSQL Serverデータベースにオブジェクトを挿入します。しかし、私はCreateメソッドを実行すると、この成功は、エラーを表示しないで、データベースには空です:/。オブジェクトを挿入するEFが動作しない

public class ProductoEntity 
{ 
     public int ID { get; set; } 
     public string Descripcion { get; set; } 
     public string Categoria { get; set; } 
     public int Precio { get; set; } 


     public Producto toSql() 
     { 
      var sqlEntity = new Producto(); 
      sqlEntity.Descripcion = this.Descripcion; 
      sqlEntity.Categoria = this.Categoria; 
      sqlEntity.Precio = this.Precio; 

      return sqlEntity; 
     } 

     public bool Create() 
     { 
      bool result = false; 

      try 
      { 
       StoreEntities context = new StoreEntities(); 
       context.Producto.Add(toSql()); ; 
       result = true; 
      } 
      catch (Exception ex) 
      { 
       throw new Exception(ex.Message); 
      } 

      return result; 
     } 
} 

答えて

6

あなたがSaveChanges

StoreEntities context = new StoreEntities(); 
context.Producto.Add(toSql()); 
context.SaveChanges(); 
を呼び出す必要があります
関連する問題