Hola a todos/as
Tengo un problema a ver si me podéis decir qué estoy haciendo mal. Tengo dos entidades:
public partial class Unit_Measure
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Unit_Measure()
{
this.PropertiesCharacs = new HashSet<PropertiesCharac>();
}
public int ID { get; set; }
public string Description { get; set; }
public string Type_Measure { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PropertiesCharac> PropertiesCharacs { get; set; }
}
public partial class PropertiesCharac
{
public int IDProp { get; set; }
public Nullable<int> IDUnit { get; set; }
public Nullable<decimal> MaxValue { get; set; }
public Nullable<decimal> MinValue { get; set; }
public Nullable<decimal> LimitHigh { get; set; }
public Nullable<decimal> LimitLow { get; set; }
public string DescValue0 { get; set; }
public string DescValue1 { get; set; }
public virtual Property Property { get; set; }
public virtual Unit_Measure Unit_Measure { get; set; }
}
Estoy intentando insertar registros en la entidad Unit_Measure. Para ello, utilizo este método:
public bool Add(string desc, string tm)
{
using (var ctx = new DBAssetsEntities())
{
//PropertiesCharac pc = new PropertiesCharac();
var um = new Unit_Measure { Description = desc, Type_Measure = tm };
um.PropertiesCharacs = new List<PropertiesCharac>();
ctx.Unit_Measure.Add(um);
ctx.SaveChanges();
return true;
}
}
El problema es que el registro, me lo inserta, pero me sale el siguiente error: "El descriptor de acceso de la propiedad 'PropertiesCharacs' inició la excepción 'The ObjectContext instance has been disposed and can no longer be used fot operations that
require a connection'"
Alguien me puede decir qué puede estar pasando??
Saludos!