【发布时间】:2018-01-10 17:59:10
【问题描述】:
我想将对象插入到 sql server 数据库中,我使用的是 EF 6.x。但是当我执行 Create 方法时,这个成功并且没有显示任何错误但在数据库中是空的:/。
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;
}
}
【问题讨论】:
标签: c# sql frameworks entity crud