Witam.
Stanąłem w martwym punkcie z połączeniem bazy danych MySQL przez EF.
Mianowicie Select do bazy danych idzie bez problem ale inne operacje "Add","Update","Delete" nie działają i objawiają się tym samym błędem.
w momencie zapisu do bazy danych czyli
db.SaveChanges();
dają następujący błąd:
An exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Stworzyłem tabele testową z 1 polem typu VARCHAR[25] i nadal nic.
Kod na którym działam jest to kod automatycznie generowany przez VS 2013.
using System;
using System.Collections.Generic;
public partial class testowa
{
public string Nazwa { get; set; }
}
// GET: testowas/Create
public ActionResult Create()
{
return View();
}
// POST: testowas/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(testowa testowa)
{
if (ModelState.IsValid)
{
db.testowa.Add(testowa);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(testowa);
}
// GET: testowas/Edit/5
public ActionResult Edit(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
testowa testowa = db.testowa.Find(id);
if (testowa == null)
{
return HttpNotFound();
}
return View(testowa);
}
// POST: testowas/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Nazwa")] testowa testowa)
{
if (ModelState.IsValid)
{
db.Entry(testowa).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(testowa);
}
// GET: testowas/Delete/5
public ActionResult Delete(string id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
testowa testowa = db.testowa.Find(id);
if (testowa == null)
{
return HttpNotFound();
}
return View(testowa);
}