数据库与仓储位置Source/DataBases项目作用H.DataBases.Share数据库共享代码。H.DataBases.SqliteSqlite 支持。H.DataBases.SqlServerSQL Server 支持。Repository 相关H.Extensions.DataBase.Repository H.Presenters.Repository H.Controls.RepositoryBox H.Test.RepositoryPresenter思路数据库模型 - 仓储服务 - Presenter - RepositoryBox 页面适合快速生成 CRUD 管理页面。DataBases 数据库系统详解一、数据库系统概述WPF-Control 的数据库系统基于Entity Framework构建提供了完整的仓储模式实现支持 Sqlite 和 SQL Server 两种数据库。核心架构数据库模型 → 仓储服务 → Presenter → RepositoryBox 页面这种设计使得开发者可以快速生成 CRUD 管理页面无需从头编写数据库操作代码。二、数据库项目结构2.1 项目组成Source/DataBases/ ├── H.DataBases.Share/ # 共享代码 │ ├── Provider/ │ │ ├── RepositoryBase.cs # 仓储基类 │ │ ├── DbContextRepository.cs # DbContext仓储 │ │ └── StringRepositoryBase.cs # 字符串主键仓储 │ ├── DbConnectServiceBase.cs # 数据库连接服务基类 │ ├── DbDisconnectService.cs # 数据库断开服务 │ ├── DbSettableBase.cs # 数据库设置基类 │ └── IDbSetting.cs # 数据库设置接口 ├── H.DataBases.Sqlite/ # Sqlite 支持 └── H.DataBases.SqlServer/ # SQL Server 支持2.2 Repository 相关模块模块作用H.Extensions.DataBase.Repository可绑定的仓储实现H.Presenters.Repository仓储展示器H.Controls.RepositoryBox仓储数据页面控件H.Test.RepositoryPresenter测试用仓储展示器三、核心概念3.1 实体基类框架提供了多种实体基类// 通用实体基类publicabstractclassEntityBaseTPrimaryKey:IEntityBaseTPrimaryKey{publicTPrimaryKeyID{get;set;}}// 字符串主键实体publicabstractclassStringEntityBase:EntityBasestring{publicStringEntityBase(){IDGuid.NewGuid().ToString();}}// Guid主键实体publicabstractclassGuidEntityBase:EntityBaseGuid{publicGuidEntityBase(){IDGuid.NewGuid();}}3.2 仓储接口publicinterfaceIRepositoryTEntity,TPrimaryKey{// 查询TaskListTEntityGetListAsync();TaskTEntityGetByIDAsync(TPrimaryKeyid);TaskTEntityFirstOrDefaultAsync(ExpressionFuncTEntity,boolpredicate);// 新增TaskintInsertAsync(TEntityentity,boolautoSavetrue);TaskintInsertRangeAsync(paramsTEntity[]entity);// 更新TaskintUpdateAsync(TEntityentity,boolautoSavetrue);// 删除TaskintDeleteAsync(TEntityentity,boolautoSavetrue);TaskintDeleteByIDAsync(TPrimaryKeyid,boolautoSavetrue);// 分页TaskTupleListTEntity,intLoadPageList(intstartPage,intpageSize,ExpressionFuncTEntity,boolwherenull,ExpressionFuncTEntity,objectordernull);// 保存TaskintSaveAsync();}四、RepositoryBase 详解4.1 仓储基类实现RepositoryBase是所有仓储的基类提供了完整的 CRUD 操作publicabstractclassRepositoryBaseTDbContext,TEntity,TPrimaryKey:IRepositoryTEntity,TPrimaryKeywhereTEntity:EntityBaseTPrimaryKeywhereTDbContext:DbContext{protectedreadonlyTDbContext_dbContext;publicRepositoryBase(TDbContextdbContext){_dbContextdbContext;}// 获取所有实体publicasyncTaskListTEntityGetListAsync(){returnawait_dbContext.SetTEntity().ToListAsync();}// 根据主键获取实体publicasyncTaskTEntityGetByIDAsync(TPrimaryKeyid){returnawait_dbContext.SetTEntity().FirstOrDefaultAsync(CreateEqualityExpressionForId(id));}// 新增实体publicasyncTaskintInsertAsync(TEntityentity,boolautoSavetrue){_dbContext.SetTEntity().Add(entity);if(autoSave)returnawaitSaveAsync();return-1;}// 更新实体publicasyncTaskintUpdateAsync(TEntityentity,boolautoSavetrue){TEntityobjawaitGetByIDAsync(entity.ID);EntityToEntity(entity,obj);// 属性拷贝if(autoSave)returnawaitSaveAsync();return-1;}// 删除实体publicasyncTaskintDeleteAsync(TEntityentity,boolautoSavetrue){_dbContext.SetTEntity().Remove(entity);if(autoSave)returnawaitSaveAsync();return-1;}// 分页查询publicasyncTaskTupleListTEntity,intLoadPageList(intstartPage,intpageSize,ExpressionFuncTEntity,boolwherenull,ExpressionFuncTEntity,objectordernull){IQueryableTEntityresult_dbContext.SetTEntity();if(where!null)resultresult.Where(where);if(order!null)resultresult.OrderBy(order);introwCountawaitresult.CountAsync();ListTEntitydataawaitresult.Skip((startPage-1)*pageSize).Take(pageSize).ToListAsync();returnTuple.Create(data,rowCount);}}4.2 使用示例步骤1创建实体类publicclassUser:StringEntityBase{publicstringName{get;set;}publicstringEmail{get;set;}publicintAge{get;set;}publicDateTimeCreateTime{get;set;}DateTime.Now;}步骤2创建 DbContextpublicclassAppDbContext:DbContext{publicDbSetUserUsers{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseSqlite(Data Sourceapp.db);}}步骤3创建仓储publicclassUserRepository:RepositoryBaseAppDbContext,User,string{publicUserRepository(AppDbContextdbContext):base(dbContext){}// 自定义查询方法publicasyncTaskListUserGetUsersByAge(intminAge,intmaxAge){returnawait_dbContext.Users.Where(uu.AgeminAgeu.AgemaxAge).ToListAsync();}}步骤4注册服务protectedoverridevoidConfigureServices(IServiceCollectionservices){services.AddDbContextAppDbContext();services.AddSingletonIRepositoryUser,string,UserRepository();}五、RepositoryBindable - 可绑定仓储5.1 概念RepositoryBindable是专为 WPF 数据绑定设计的仓储包装类它继承BindableBase支持属性变化通知自动管理数据集合提供增删改查的绑定命令5.2 使用示例publicclassUserRepositoryBindable:RepositoryBindableUser{// 可以重写 Where 方法进行过滤protectedoverrideboolWhere(Userentity){// 只显示年龄大于18的用户returnentity.Age18;}// 可以重写 CreateSelectBindable 自定义包装protectedoverrideSelectBindableUserCreateSelectBindable(Userentity){returnnewSelectBindableUser(entity);}}5.3 绑定到 UI!-- RepositoryBox 控件 --controls:RepositoryBoxRepository{Binding UserRepository}DataContext{Binding}/六、完整 CRUD 流程6.1 架构流程图┌─────────────────────────────────────────────────────────────────┐ │ 数据库层 │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ Sqlite │ │ SQL Server │ │ Other │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ 仓储层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBaseTEntity, TPrimaryKey │ │ │ │ - GetList() / GetListAsync() │ │ │ │ - GetByID() / GetByIDAsync() │ │ │ │ - Insert() / InsertAsync() │ │ │ │ - Update() / UpdateAsync() │ │ │ │ - Delete() / DeleteAsync() │ │ │ │ - LoadPageList() │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ RepositoryBindable层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBindableTEntity │ │ │ │ - Collection (ObservableCollection) │ │ │ │ - Add() / Remove() / RefreshData() │ │ │ │ - Commands (AddCommand, DeleteCommand, etc.) │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ Presenter层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryPresenterTEntity │ │ │ │ - 绑定 RepositoryBindable │ │ │ │ - 提供 UI 交互逻辑 │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ UI层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBox / DataGridPresenter │ │ │ │ - 自动显示数据列表 │ │ │ │ - 提供增删改查按钮 │ │ │ └─────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────┘6.2 代码示例ViewModelpublicclassUserManagementViewModel:BindableBase{publicRepositoryBindableUserUserRepository{get;}publicUserManagementViewModel(RepositoryBindableUseruserRepository){UserRepositoryuserRepository;UserRepository.RefreshData();// 加载数据}// 新增用户publicICommandAddUserCommandnewRelayCommand((){UsernewUsernewUser{Name新用户,Emailnewexample.com,Age25};UserRepository.Add(newUser);});// 删除选中用户publicICommandDeleteSelectedCommandnewRelayCommand((){varselectedUserRepository.Collection.Where(xx.IsSelected).Select(xx.Entity).ToArray();UserRepository.Remove(selected);});}XAMLWindow.DataContextviewModels:UserManagementViewModel//Window.DataContextGrid!-- 工具栏 --StackPanelOrientationHorizontalMargin10ButtonCommand{Binding AddUserCommand}Content新增/ButtonCommand{Binding DeleteSelectedCommand}Content删除选中/ButtonCommand{Binding UserRepository.RefreshCommand}Content刷新//StackPanel!-- 数据列表 --controls:RepositoryBoxRepository{Binding UserRepository}Margin10//Grid七、数据库连接服务7.1 SqlServer 连接// 注册 SqlServer 服务services.AddSqlServer();// 配置连接字符串services.ConfigureISqlServerOption(options{options.ConnectionStringServerlocalhost;DatabaseMyDB;Trusted_ConnectionTrue;;});7.2 Sqlite 连接// 注册 Sqlite 服务services.AddSqlite();// 配置连接字符串services.ConfigureISqliteOption(options{options.ConnectionStringData Sourceapp.db;});八、最佳实践8.1 实体设计// ✅ 推荐继承合适的基类publicclassProduct:StringEntityBase{publicstringName{get;set;}publicdecimalPrice{get;set;}publicintStock{get;set;}// 添加索引属性[Index]publicstringCategory{get;set;}}8.2 仓储使用// ✅ 推荐通过构造函数注入publicclassProductService{privatereadonlyIRepositoryProduct,string_repository;publicProductService(IRepositoryProduct,stringrepository){_repositoryrepository;}publicasyncTaskListProductGetProductsByCategory(stringcategory){returnawait_repository.GetListAsync(pp.Categorycategory);}}8.3 事务处理// ✅ 推荐使用 SaveChanges 进行事务提交using(vartransactionawait_dbContext.Database.BeginTransactionAsync()){try{// 多个操作await_repository.InsertAsync(product1);await_repository.InsertAsync(product2);await_dbContext.SaveChangesAsync();awaittransaction.CommitAsync();}catch{awaittransaction.RollbackAsync();throw;}}九、总结数据库系统是 WPF-Control 的数据访问核心支持多数据库Sqlite、SQL Server仓储模式RepositoryBase 提供完整 CRUD可绑定仓储RepositoryBindable 适配 WPF 绑定快速构建RepositoryBox 一键生成管理页面使用流程定义实体类继承StringEntityBase或GuidEntityBase创建DbContext创建仓储类继承RepositoryBase注册服务使用RepositoryBindable绑定到 UI使用RepositoryBox显示数据这套体系可以极大简化数据库操作让开发者专注于业务逻辑。
数据库与仓储
数据库与仓储位置Source/DataBases项目作用H.DataBases.Share数据库共享代码。H.DataBases.SqliteSqlite 支持。H.DataBases.SqlServerSQL Server 支持。Repository 相关H.Extensions.DataBase.Repository H.Presenters.Repository H.Controls.RepositoryBox H.Test.RepositoryPresenter思路数据库模型 - 仓储服务 - Presenter - RepositoryBox 页面适合快速生成 CRUD 管理页面。DataBases 数据库系统详解一、数据库系统概述WPF-Control 的数据库系统基于Entity Framework构建提供了完整的仓储模式实现支持 Sqlite 和 SQL Server 两种数据库。核心架构数据库模型 → 仓储服务 → Presenter → RepositoryBox 页面这种设计使得开发者可以快速生成 CRUD 管理页面无需从头编写数据库操作代码。二、数据库项目结构2.1 项目组成Source/DataBases/ ├── H.DataBases.Share/ # 共享代码 │ ├── Provider/ │ │ ├── RepositoryBase.cs # 仓储基类 │ │ ├── DbContextRepository.cs # DbContext仓储 │ │ └── StringRepositoryBase.cs # 字符串主键仓储 │ ├── DbConnectServiceBase.cs # 数据库连接服务基类 │ ├── DbDisconnectService.cs # 数据库断开服务 │ ├── DbSettableBase.cs # 数据库设置基类 │ └── IDbSetting.cs # 数据库设置接口 ├── H.DataBases.Sqlite/ # Sqlite 支持 └── H.DataBases.SqlServer/ # SQL Server 支持2.2 Repository 相关模块模块作用H.Extensions.DataBase.Repository可绑定的仓储实现H.Presenters.Repository仓储展示器H.Controls.RepositoryBox仓储数据页面控件H.Test.RepositoryPresenter测试用仓储展示器三、核心概念3.1 实体基类框架提供了多种实体基类// 通用实体基类publicabstractclassEntityBaseTPrimaryKey:IEntityBaseTPrimaryKey{publicTPrimaryKeyID{get;set;}}// 字符串主键实体publicabstractclassStringEntityBase:EntityBasestring{publicStringEntityBase(){IDGuid.NewGuid().ToString();}}// Guid主键实体publicabstractclassGuidEntityBase:EntityBaseGuid{publicGuidEntityBase(){IDGuid.NewGuid();}}3.2 仓储接口publicinterfaceIRepositoryTEntity,TPrimaryKey{// 查询TaskListTEntityGetListAsync();TaskTEntityGetByIDAsync(TPrimaryKeyid);TaskTEntityFirstOrDefaultAsync(ExpressionFuncTEntity,boolpredicate);// 新增TaskintInsertAsync(TEntityentity,boolautoSavetrue);TaskintInsertRangeAsync(paramsTEntity[]entity);// 更新TaskintUpdateAsync(TEntityentity,boolautoSavetrue);// 删除TaskintDeleteAsync(TEntityentity,boolautoSavetrue);TaskintDeleteByIDAsync(TPrimaryKeyid,boolautoSavetrue);// 分页TaskTupleListTEntity,intLoadPageList(intstartPage,intpageSize,ExpressionFuncTEntity,boolwherenull,ExpressionFuncTEntity,objectordernull);// 保存TaskintSaveAsync();}四、RepositoryBase 详解4.1 仓储基类实现RepositoryBase是所有仓储的基类提供了完整的 CRUD 操作publicabstractclassRepositoryBaseTDbContext,TEntity,TPrimaryKey:IRepositoryTEntity,TPrimaryKeywhereTEntity:EntityBaseTPrimaryKeywhereTDbContext:DbContext{protectedreadonlyTDbContext_dbContext;publicRepositoryBase(TDbContextdbContext){_dbContextdbContext;}// 获取所有实体publicasyncTaskListTEntityGetListAsync(){returnawait_dbContext.SetTEntity().ToListAsync();}// 根据主键获取实体publicasyncTaskTEntityGetByIDAsync(TPrimaryKeyid){returnawait_dbContext.SetTEntity().FirstOrDefaultAsync(CreateEqualityExpressionForId(id));}// 新增实体publicasyncTaskintInsertAsync(TEntityentity,boolautoSavetrue){_dbContext.SetTEntity().Add(entity);if(autoSave)returnawaitSaveAsync();return-1;}// 更新实体publicasyncTaskintUpdateAsync(TEntityentity,boolautoSavetrue){TEntityobjawaitGetByIDAsync(entity.ID);EntityToEntity(entity,obj);// 属性拷贝if(autoSave)returnawaitSaveAsync();return-1;}// 删除实体publicasyncTaskintDeleteAsync(TEntityentity,boolautoSavetrue){_dbContext.SetTEntity().Remove(entity);if(autoSave)returnawaitSaveAsync();return-1;}// 分页查询publicasyncTaskTupleListTEntity,intLoadPageList(intstartPage,intpageSize,ExpressionFuncTEntity,boolwherenull,ExpressionFuncTEntity,objectordernull){IQueryableTEntityresult_dbContext.SetTEntity();if(where!null)resultresult.Where(where);if(order!null)resultresult.OrderBy(order);introwCountawaitresult.CountAsync();ListTEntitydataawaitresult.Skip((startPage-1)*pageSize).Take(pageSize).ToListAsync();returnTuple.Create(data,rowCount);}}4.2 使用示例步骤1创建实体类publicclassUser:StringEntityBase{publicstringName{get;set;}publicstringEmail{get;set;}publicintAge{get;set;}publicDateTimeCreateTime{get;set;}DateTime.Now;}步骤2创建 DbContextpublicclassAppDbContext:DbContext{publicDbSetUserUsers{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseSqlite(Data Sourceapp.db);}}步骤3创建仓储publicclassUserRepository:RepositoryBaseAppDbContext,User,string{publicUserRepository(AppDbContextdbContext):base(dbContext){}// 自定义查询方法publicasyncTaskListUserGetUsersByAge(intminAge,intmaxAge){returnawait_dbContext.Users.Where(uu.AgeminAgeu.AgemaxAge).ToListAsync();}}步骤4注册服务protectedoverridevoidConfigureServices(IServiceCollectionservices){services.AddDbContextAppDbContext();services.AddSingletonIRepositoryUser,string,UserRepository();}五、RepositoryBindable - 可绑定仓储5.1 概念RepositoryBindable是专为 WPF 数据绑定设计的仓储包装类它继承BindableBase支持属性变化通知自动管理数据集合提供增删改查的绑定命令5.2 使用示例publicclassUserRepositoryBindable:RepositoryBindableUser{// 可以重写 Where 方法进行过滤protectedoverrideboolWhere(Userentity){// 只显示年龄大于18的用户returnentity.Age18;}// 可以重写 CreateSelectBindable 自定义包装protectedoverrideSelectBindableUserCreateSelectBindable(Userentity){returnnewSelectBindableUser(entity);}}5.3 绑定到 UI!-- RepositoryBox 控件 --controls:RepositoryBoxRepository{Binding UserRepository}DataContext{Binding}/六、完整 CRUD 流程6.1 架构流程图┌─────────────────────────────────────────────────────────────────┐ │ 数据库层 │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ Sqlite │ │ SQL Server │ │ Other │ │ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ │ │ │ │ ▼ ▼ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ 仓储层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBaseTEntity, TPrimaryKey │ │ │ │ - GetList() / GetListAsync() │ │ │ │ - GetByID() / GetByIDAsync() │ │ │ │ - Insert() / InsertAsync() │ │ │ │ - Update() / UpdateAsync() │ │ │ │ - Delete() / DeleteAsync() │ │ │ │ - LoadPageList() │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ RepositoryBindable层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBindableTEntity │ │ │ │ - Collection (ObservableCollection) │ │ │ │ - Add() / Remove() / RefreshData() │ │ │ │ - Commands (AddCommand, DeleteCommand, etc.) │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ Presenter层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryPresenterTEntity │ │ │ │ - 绑定 RepositoryBindable │ │ │ │ - 提供 UI 交互逻辑 │ │ │ └──────────────────────┬──────────────────────────────┘ │ │ │ │ │ ▼ │ ├─────────────────────────────────────────────────────────────────┤ │ UI层 │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ RepositoryBox / DataGridPresenter │ │ │ │ - 自动显示数据列表 │ │ │ │ - 提供增删改查按钮 │ │ │ └─────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────┘6.2 代码示例ViewModelpublicclassUserManagementViewModel:BindableBase{publicRepositoryBindableUserUserRepository{get;}publicUserManagementViewModel(RepositoryBindableUseruserRepository){UserRepositoryuserRepository;UserRepository.RefreshData();// 加载数据}// 新增用户publicICommandAddUserCommandnewRelayCommand((){UsernewUsernewUser{Name新用户,Emailnewexample.com,Age25};UserRepository.Add(newUser);});// 删除选中用户publicICommandDeleteSelectedCommandnewRelayCommand((){varselectedUserRepository.Collection.Where(xx.IsSelected).Select(xx.Entity).ToArray();UserRepository.Remove(selected);});}XAMLWindow.DataContextviewModels:UserManagementViewModel//Window.DataContextGrid!-- 工具栏 --StackPanelOrientationHorizontalMargin10ButtonCommand{Binding AddUserCommand}Content新增/ButtonCommand{Binding DeleteSelectedCommand}Content删除选中/ButtonCommand{Binding UserRepository.RefreshCommand}Content刷新//StackPanel!-- 数据列表 --controls:RepositoryBoxRepository{Binding UserRepository}Margin10//Grid七、数据库连接服务7.1 SqlServer 连接// 注册 SqlServer 服务services.AddSqlServer();// 配置连接字符串services.ConfigureISqlServerOption(options{options.ConnectionStringServerlocalhost;DatabaseMyDB;Trusted_ConnectionTrue;;});7.2 Sqlite 连接// 注册 Sqlite 服务services.AddSqlite();// 配置连接字符串services.ConfigureISqliteOption(options{options.ConnectionStringData Sourceapp.db;});八、最佳实践8.1 实体设计// ✅ 推荐继承合适的基类publicclassProduct:StringEntityBase{publicstringName{get;set;}publicdecimalPrice{get;set;}publicintStock{get;set;}// 添加索引属性[Index]publicstringCategory{get;set;}}8.2 仓储使用// ✅ 推荐通过构造函数注入publicclassProductService{privatereadonlyIRepositoryProduct,string_repository;publicProductService(IRepositoryProduct,stringrepository){_repositoryrepository;}publicasyncTaskListProductGetProductsByCategory(stringcategory){returnawait_repository.GetListAsync(pp.Categorycategory);}}8.3 事务处理// ✅ 推荐使用 SaveChanges 进行事务提交using(vartransactionawait_dbContext.Database.BeginTransactionAsync()){try{// 多个操作await_repository.InsertAsync(product1);await_repository.InsertAsync(product2);await_dbContext.SaveChangesAsync();awaittransaction.CommitAsync();}catch{awaittransaction.RollbackAsync();throw;}}九、总结数据库系统是 WPF-Control 的数据访问核心支持多数据库Sqlite、SQL Server仓储模式RepositoryBase 提供完整 CRUD可绑定仓储RepositoryBindable 适配 WPF 绑定快速构建RepositoryBox 一键生成管理页面使用流程定义实体类继承StringEntityBase或GuidEntityBase创建DbContext创建仓储类继承RepositoryBase注册服务使用RepositoryBindable绑定到 UI使用RepositoryBox显示数据这套体系可以极大简化数据库操作让开发者专注于业务逻辑。