2017-08-03 4 views
0

Ich möchte Objekt in die SQL Server-Datenbank einfügen, ich verwende EF 6.x. Aber wenn ich Create-Methode ausführen, ist dieser Erfolg und kein Fehler angezeigt, aber in einer Datenbank ist leer: /.Objekt einfügen EF funktioniert nicht

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

Antwort

6

Sie benötigen SaveChanges

StoreEntities context = new StoreEntities(); 
context.Producto.Add(toSql()); 
context.SaveChanges(); 
nennen