I have 2 sql tables which are very similar. Only the Foreign Key is different for each table.
TemplateUnit table:
Id (PK)
ParentId
Name
TemplateId (FK)
TestplanUnit table:
Id (PK)
ParentId
Name
TestplanId (FK)
When I go for 2 tables which has the nearly same content - just the FK is different - do you really create duplicates of your CRUD methods in your service and dataprovider (using ado.net pure) ?
How would improve the service so only one kind of Get/Add/Update/Delete methods is used in the service and dataprovider class? I also do not want to make duplicate unit tests...
UPDATE:
This is my solution so far:
public class Unit
{
public string Name { get; set; }
public int Id { get; set; }
public Nullable<int> ParentId { get; set; }
public int TemplateId { get; set; }
public bool IsLazy { get; set; }
}
public class UnitDTO
{
public UnitDTO(UnitMode mode)
{
switch (mode)
{
case UnitMode.Template:
this.ForeinKeyName = "TemplateId";
this.TableName = "TemplateUnit";
break;
case UnitMode.Testplan:
this.ForeinKeyName = "TestplanId";
this.TableName = "TestplanUnit";
break;
}
UnitBO = new Unit();
}
public string TableName { get; private set; }
public string ForeinKeyName { get; private set; }
public Unit UnitBO { get; private set; }
}
public enum UnitMode
{
Template = 0,
Testplan = 1,
}
My Get/Add/Delete methods in BLL and DAL get a UnitDTO object with all information needed.
Well one disadvantage could be - if this project would be done in a team - that you have to know which variable is used/needed in the DAL when you create the UnitDTO and pass it to the BLL for each CRUD method.
What do you think?