0

I am currently working on a ASP.NET MVC 3 Project where I have to maintain Statuses for about 60+ Database Models. E.g.

Parent:

public class DistributorModel 
{
  public DistributorModel()
  {
    Title = "Distributor";     
  }

  public int DistributorId { get; set; }

  public string Code { get; set; }

  public string DistributorName { get; set; }

  public ActiveStatus IsActive { get; set; }
}

Child:

public class DistributorVehicleModel 
{
  public DistributorModel()
  {
    Title = "Distributor Vehicle";     
  }

  public int DistributorVehicleId { get; set; }

  public string Make { get; set; }

  public string Model { get; set; }

  public int DistributorId { get; set; } // This is the foreign key

  public ActiveStatus IsActive { get; set; }
}

The problem with maintaining statuses for both parent and child is as follows:

First: When you change the status of a Distributor to be Inactive, none of it's vehicles may be active, which is the required result. But how do you update the status of all the children - there could be multiple child objects? Without explicitly specifiying which children to update (or at least minimize the amount of calls)? This might be a bit ambitious.

Second: A second approach I thought might work is to remove the status field in the Vehicle Model, however a vehicle's status can be set to inactive due to repairs being done etc, so this won't really help and you don't want to delete a vehicle record and add it again in 5 days when it is repaired. What would be the best approach?

I have considered using database triggers, but I would prefer to keep the functionality at programming level for future project templates which might not use MS SQL Server 2008.

What will be the best approach to maintain the statuses of these entities? Without opening a can of worms. I am NOT using Entity Framework

4

0 回答 0