0

I am using .NET MVC 5 and entity framework I have this model :

public class Division
{
    public int Id { get; set; }

    [Required]
    [StringLength(50)]
    public string Name { get; set; }

    public virtual IList<Department> Departments { get; set; }

    [Display(Name = "Manager")]
    public string ManagerId { get; set; }

    [ForeignKey("ManagerId")]
    public virtual AppUser Manager { get; set; }

    public virtual IList<AppUser> Users { get; set; }
}

So the Division Has a Manager.

When I keep the App running for a while, All related managers are removed without me doing any thing ! Only the relation is removed ( ManagerId = null ) instead of the Id, but they still there in the Users table.

Any suggestions will be appreciated.

(Edit) Thank you Carl,
I put a Trigger on the table divisions, and I noticed that it get updated when I leave the app running for a while and then try to enter any page !

sami
  • 79
  • 1
  • 6
  • What actions are allowed on this entity? e.g. edit, delete? is the model posted your viewmodel as well as your database object? are you looking for a code reason for this happening, or foul play by a user? – Carl Sep 16 '14 at 18:30
  • Actions are allowed depending on the user role, so the Admin can edit and delete. – sami Sep 16 '14 at 19:50
  • It's used in some views as the ViewModel. The App is not published yet, so I am the only user, something strange is happening with the code think ! – sami Sep 16 '14 at 19:52
  • Is there a way to watch a specific table to know when it changes ? and what changes it ? – sami Sep 17 '14 at 04:41
  • You could run sql profiler - you need sql web or sql dev for this, i don't think it comes with express, or put a sql trigger on the table for update, and log as much info as you can. If you are running your app in debug, put a breakpoint on any code that commits to the db for this or related objects, giving you the chance to check the db before and after the commit. – Carl Sep 17 '14 at 06:20
  • If you are using it as a view model, and if manager is not populated after a post, its possible that it's being interpreted as you removing the manager object - this depends how your update code works - maybe post your controller and save method? – Carl Sep 17 '14 at 06:24

1 Answers1

0

The problem was solved when I published without enabling ( running migration with the app first start up ).

I don't know the exact reason but I think when I leave the app running for a while and then enter any page, the Seed method was running again.

sami
  • 79
  • 1
  • 6