namespace SolucionesEfectivas.Models
{
using System;
using System.Collections.Generic;
public partial class sucursal
{
public sucursal()
{
this.buro = new HashSet<buro>();
this.caja = new HashSet<caja>();
this.cliente = new HashSet<cliente>();
this.cuenta = new HashSet<cuenta>();
this.cuentadestino = new HashSet<cuentadestino>();
this.empleado = new HashSet<empleado>();
}
public int id { get; set; }
public int idoficina { get; set; }
public string nombreoficina { get; set; }
public string nombreencargado { get; set; }
public string apencargado { get; set; }
public string amencargado { get; set; }
public int codigopostal { get; set; }
public string estado { get; set; }
public string municipio { get; set; }
public string colonia { get; set; }
public string calle { get; set; }
public int numeroext { get; set; }
public Nullable<int> numeroint { get; set; }
public string telefono { get; set; }
public virtual ICollection<buro> buro { get; set; }
public virtual ICollection<caja> caja { get; set; }
public virtual ICollection<cliente> cliente { get; set; }
public virtual ICollection<cuenta> cuenta { get; set; }
public virtual ICollection<cuentadestino> cuentadestino { get; set; }
public virtual ICollection<empleado> empleado { get; set; }
public virtual oficina oficina { get; set; }
}
}
and here is my controller:
public ActionResult Create()
{
ViewBag.idoficina = new SelectList(db.oficina, "id", "descripcion");
return View();
}
//
// POST: /Sucursal/Create
[HttpPost]
public ActionResult Create(sucursal sucursal)
{
if (ModelState.IsValid)
{
db.sucursal.Add(sucursal);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.idoficina = new SelectList(db.oficina, "id", "descripcion", sucursal.idoficina);
return View(sucursal);
}
I really don´t now why its happend, I debugg my proyect and in the part of database the field oficina return NULL, but oficina it´s only a virtual collertion in my model that it´s catched in my controller whit idoficina.
Please someone helps
P.D. my models, controllers ands views whas created whit EF I really only put my database.
Memnoch1984
Member
8 Points
32 Posts
please help!!! Validation failed for one or more entities. See 'EntityValidationErrors' property ...
Mar 28, 2012 03:54 PM|LINK
Here is my model
namespace SolucionesEfectivas.Models { using System; using System.Collections.Generic; public partial class sucursal { public sucursal() { this.buro = new HashSet<buro>(); this.caja = new HashSet<caja>(); this.cliente = new HashSet<cliente>(); this.cuenta = new HashSet<cuenta>(); this.cuentadestino = new HashSet<cuentadestino>(); this.empleado = new HashSet<empleado>(); } public int id { get; set; } public int idoficina { get; set; } public string nombreoficina { get; set; } public string nombreencargado { get; set; } public string apencargado { get; set; } public string amencargado { get; set; } public int codigopostal { get; set; } public string estado { get; set; } public string municipio { get; set; } public string colonia { get; set; } public string calle { get; set; } public int numeroext { get; set; } public Nullable<int> numeroint { get; set; } public string telefono { get; set; } public virtual ICollection<buro> buro { get; set; } public virtual ICollection<caja> caja { get; set; } public virtual ICollection<cliente> cliente { get; set; } public virtual ICollection<cuenta> cuenta { get; set; } public virtual ICollection<cuentadestino> cuentadestino { get; set; } public virtual ICollection<empleado> empleado { get; set; } public virtual oficina oficina { get; set; } } }and here is my controller:
public ActionResult Create() { ViewBag.idoficina = new SelectList(db.oficina, "id", "descripcion"); return View(); } // // POST: /Sucursal/Create [HttpPost] public ActionResult Create(sucursal sucursal) { if (ModelState.IsValid) { db.sucursal.Add(sucursal); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.idoficina = new SelectList(db.oficina, "id", "descripcion", sucursal.idoficina); return View(sucursal); }Here es the stack error:
I really don´t now why its happend, I debugg my proyect and in the part of database the field oficina return NULL, but oficina it´s only a virtual collertion in my model that it´s catched in my controller whit idoficina.
Please someone helps
P.D. my models, controllers ands views whas created whit EF I really only put my database.
Memnoch1984
Member
8 Points
32 Posts
Re: please help!!! Validation failed for one or more entities. See 'EntityValidationErrors' prope...
Mar 28, 2012 04:33 PM|LINK
I found the error, jejeje my partner put char in some data and I was traing to introduce nvarchar, jeje
Thanks.
habeeb_matri...
Member
12 Points
15 Posts
Re: please help!!! Validation failed for one or more entities. See 'EntityValidationErrors' prope...
Oct 24, 2012 09:47 AM|LINK
Here is a readymade catch block to get into the real issue that throws this exception from the entity framework.
http://dotnet-programming-solutions.blogspot.com/2012/10/validation-failed-for-one-or-more_24.html