模型:
public class Student
{
public int StudentID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Gender Gender { get; set; }
public string Address { get; set; }
}
数据库上下文:
public class MyContext : DbContext
{
public MyContext():base(connectionstring)
{
}
public DbSet<Student> Student { get; set; }
}
包装类:
public class StudentWrapper
{
public int StudentID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Gender Gender { get; set; }
public string Address { get; set; }
}
执行:
public void AddStudent()
{
using(MyContext ctx = new MyContext())
{
StudentWrapper newStudent = new StudentWrapper(); // If ever I wanted this `working`
ctx.Student.Add(newStudent);
}
}
我想为我的模型类制作一个包装器,而不是直接在 CRUD 操作中使用我的模型,这样做是否正确?