在这里,我有一个很好的建议给你。
首先将您的应用程序划分为层
**SM.MVCApp** :- This is for MVC application
**SM.Service** :- This layer is for holding the business logic (Interface & Class)
**SM.Data** :- This layer is to interact with database using Entity framework (Repository & UOW)
**SM.Entity** :- This layer is responsible for having property in class that will be mapping with the table of database.
SM.服务示例
public interface IStudent
{
IQueryable<Entity.Student> GetAllStudent();
Student GetStudentByID(Int32 StudentID);
void CreateStudent(Student objStudent);
void UpdateStudent(Student objStudent);
void DeleteStudentvoid(Student objStudent);
void SaveChanges();
List<Entity.Student> SearchStudent(string Name, int Age, string EmailAddress, string CountryName);
void MakeRelation(Entity.StudentCourceMap objMap);
}
现在展示如何创建 SM.Data 层
- 首先创建用于创建数据库和表的 DBContext 类
- 然后为 crud 操作创建 IRepository * Repository 类
- 然后创建 UOW(工作单元)