Am using EF 6.0 for my web application, whenever i tried to save or update data via EF, it throws a "null reference exception".. this method is responsible for creating products
private Product createProduct()
{
Product product = new Product();
product.Name = txtName.Text;
product.Price = Convert.ToInt32(txtPrice.Text);
product.ProductTypeId = Convert.ToInt32(ddlType.SelectedValue);
product.Desciption = txtDesciption.Text;
product.Image = ddlImage.SelectedValue;
return product;
}
this method is calling "insert product method"
protected void btnSubmit_Click(object sender, EventArgs e)
{
ProductModel model = new ProductModel();
Product product = createProduct();
lblStatus.Text = model.InsertProduct(product);
}
This method is performing "product insertion function" and it throws exception
public string InsertProduct(Product product)
{
try
{
PizzaHuttSliceEntities db = new PizzaHuttSliceEntities();
db.Products.Add(product);
db.SaveChanges();
return product.Name + "was successfully inserted! ";
}
catch (Exception e)
{
return "Error: " + e;
}
}
Here is product class
public partial class Product
{
public Product()
{
this.Carts = new HashSet<Cart>();
}
public int ID { get; set; }
public int ProductTypeId { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public string Desciption { get; set; }
public string Image { get; set; }
public virtual ICollection<Cart> Carts { get; set; }
public virtual ProductType ProductType { get; set; }
}
Here is Trace Info

System.Data.Entity.Validation.DbEntityValidationException. That exception type has a property calledEntityValidationErrorswhich contains more information about what happened. I'd look at the exception in debugger and see if you can find aDbEntityValidationExceptionburied in there.