I am setting up a Net Core page that uses several DbSets as a hook for a set of SQL tables (each table has a unique class name). Each class inherits from a general class I wrote - when the class is instantiated, only variables inside the general class are set - the derived classes are mainly for structure and are used later. Please see the example code below:
public class GeneralSet
{
[Key]
public Guid Id {get; set;}
public string set { get; set; }
public string userID { get; set; }
}
public class SpecificSetOne : GeneralSet
{
public SpecificSetOne(string _set, string _userID) : base(_set, _userID)
{
}
public string otherVariableUsedLater {get; set;}
}
public class SpecificSetTwo : GeneralSet
{
public SpecificSetTwo(string _set, string _userID) : base(_set, _userID)
{
}
public string otherVariableUsedLaterWithDifferentName {get; set;}
}
I have my DbContext set up as follows:
public class SetDbContext : DbContext
{
public SetDbContext(DbContextOptions<SetDbContext> options) :
base(options)
{
}
public DbSet<SpecificSetOne> SetOneData { get; set; }
public DbSet<SpecificSetTwo> SetTwoData { get; set; }
}
My controllers see a string variable "set" sent via url.
I am currently writing a repository to control CRUD functionality for the tables. I am trying to contain it all within one repository and to call the appropriate CRUD functionality for a specific set based on which set string is passed in via that url. Is this possible in c#? I've been reviewing reflection but am not exactly sure if what I want is doable or advisable.
Thank you very much, hopefully this is somewhat clear.
Aucun commentaire:
Enregistrer un commentaire