I'm working on a project with C# and SQL Server. I have a table called Area
and it has a column called flag
, it is a char(1)
.
I create the object with the following code:
Area objArea = new Area()
{
CodArea = txtCod.Text.ToString().ToUpper().Trim(),
NameArea= txtNombre.Text.ToString().ToUpper().Trim(),
UserCreate= Session.CurrentSession.User.User1,
DateCreate= DateTime.Now,
Flag= "A"
};
It worked okay until yesterday but now the program shows this message:
the field flag should be an string or array with length 1.
Does anybody know what is wrong?
I'm using Entity Framework, I catch the exception with the following code:
public void Insert(Area data)
{
dataBase.Area.Add(data);
try
{
dataBase.SaveChanges();
}
catch(DbEntityValidationException ex)
{
foreach(var errors in ex.EntityValidationErrors)
{
foreach(var error in errors.ValidationErrors)
{
Trace.TraceInformation("Property: {0}, Error: {1}",
error.PropertyName,
error.ErrorMessage);
}
}
}
}
Interesting fact: I have another class called Product and I send the value "A" for flag and it doesnt have any error.
This is the class, is auto-generated
public partial class Area
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Area()
{
this.Articuloes = new HashSet<Articulo>();
}
public int Id_Area { get; set; }
public string CodArea { get; set; }
public string NombreArea { get; set; }
public string UsuarioCreacion { get; set; }
public System.DateTime FechaCreacion { get; set; }
public string UsuarioModificacion { get; set; }
public Nullable<System.DateTime> FechaModificacion { get; set; }
public string Estado { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Articulo> Articuloes { get; set; }
}