I have a method that aims to update a Monitor Profile's Nodes and Attributes:
All of the primitive type of the entity (ProfileName, DisplayName) get updated fine. However, on save changes, the Attributes and Nodes do not get modified.
Here is the entity itself:
public class NWatchMonProfile
{
public NWatchMonProfile()
{
this.CasAttributes = new HashSet<NWatchAttribute>();
}
[MaxLength(50)]
public string ProfileName { get; set; }
public System.DateTime CreatedDate { get; set; }
[MaxLength(50)]
public string CreatedUser { get; set; }
public Nullable<System.DateTime> EndedDate { get; set; }
[MaxLength(50)]
public string EndedUser { get; set; }
public virtual ICollection<NWatchAttribute> CasAttributes { get; set; }
public virtual ICollection<NWatchNode> Nodes { get; set; }
}
Here is the MVC controller code that is being used to attempt to Update the record.
var monProfile = new NWatchMonProfile
{
Id = profileId,
ProfileName = profileName,
DisplayName = profileName,
CasAttributes = attributes,
Nodes = nodes
};
monProfile.CreatedDate = DateTime.Now;
monProfile.DisplayName = profileName;
monProfile.ProfileName = profileName;
if (nodes.Count > 0)
{
monProfile.Nodes = nodes;
}
monProfile.CasAttributes = attributes;
var entry = dbContext.Entry(monProfile);
entry.State = EntityState.Modified;
dbContext.SaveChanges();
Note: I have verified that the "attributes" array contains a list of NWatchAttributes. STE is no longer recommended by Microsoft.