[TrackChanges]
[Table("ExceptionType")]
public class ExceptionType
{
public int Id { get; set; }
[Required, StringLength(10, MinimumLength = 1)]
[Index("UQ_Description", 1, IsUnique = true)]
public string Description { get; set; }
public virtual ICollection<ExceptionItem> ExceptionItems { get; set; }
}
[TrackChanges]
[Table("ExceptionItem")]
public class ExceptionItem
{
public int Id { get; set; }
public string Description { get; set; }
[ForeignKey("ExceptionType")]
public int ExceptionTypeId { get; set; }
public virtual ExceptionType ExceptionType { get; set; }
}
context:
public class AppContext : TrackerContext
{
public AppContext() : base("name=DefaultConnection") { }
public DbSet<ExceptionType> ExceptionType { get; set; }
public DbSet<ExceptionItem> ExceptionItem { get; set; }
}
When savechanges will show System.Collections.Generic.KeyNotFoundException
Model:
context:
Controller:
Global.asax.cs: