I have the following object declared in C# ASP.NET MVC, which represents an object in our Azure SQL Server database.
public class Note
{
[Key]
[HiddenInput(DisplayValue = false)]
public int Id { get; set; }
[Display(Name = "Last Edited")]
[HiddenInput(DisplayValue = true)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime LastEditDateUTC { get; set; }
[StringLength(300)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
[Required(AllowEmptyStrings = true)]
public String Subject { get; set; }
[StringLength(1000)]
[DataType(DataType.MultilineText)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
[Required(AllowEmptyStrings = true)]
public String Text { get; set; }
}
This is how I would save this object to the SQL database:
Note note = new Note()
{
// Fill out all the variables
};
try
{
mySQLServer.mySQLTable.Add(note);
mySQLServer.SaveChanges();
}
catch (Exception e)
{
// Log
}
What I would like is to add one more variable to Note
named IsSelected
, but I would not like this variable to be saved to the SQL server's table when the mySQLServer.SaveChanges()
method is called, because the IsSelected
variable would be used with the UI only. Is there a Data Annotation property that can be added to IsSelected
to accomplish this? Is this use case even possible?