1.模板下载(选择MVC5.X)
https://aspnetboilerplate.com/Templates
2.还原库引用
3.迁移到MySQL
(参看:https://aspnetboilerplate.com/Pages/Documents/EF-MySql-Integration?searchKey=mysql)
(3.1) .EntityFramework 和 .Web 项目都添加MySql.Data.Entity库引用
(3.2)修改\src\MyABP.EntityFramework\Migrations下Configuration.cs文件,在public Configuration()方法中添加
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
(3.3).Web项目的web.config文件中修改链接字符串
<add name="Default" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=***" providerName="MySql.Data.MySqlClient"/>
(3.4)删除 .EntityFramework项目中migration下的类似于"201506210746108_AbpZero_Initial"这样的有时间标识的文件。
(3.5)在程序包管理控制台中,切换到.EntityFramework项目,然后执行
Add-Migration "AbpZero_Initial"和 Update-Database
数据迁移成功后即可启动项目
注意:如果提示 Specified key was too long; max key length is 767 bytes错误,则在\src\MyTestABP.EntityFramework\EntityFramework目录下...DbContext文件中添加方法:
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>(); base.OnModelCreating(modelBuilder); }
并且类之前添加定义:
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] public class MyABPDbContext : AbpZeroDbContext<Tenant, Role, User> { //........
4.对WebApi项目添加Swagger引用
(4.1)在webapi项目引用库Swashbuckle.Core
(4.2)在.....WebApiModule文件中添加方法并调用ConfigureSwaggerUi();
private void ConfigureSwaggerUi() { Configuration.Modules.AbpWebApi().HttpConfiguration .EnableSwagger(c => { c.SingleApiVersion("v1", "SwaggerIntegrationDemo.WebApi"); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); }) .EnableSwaggerUi(); }
///**********在swagger中增加token支持:
//**** Configuration.Modules.AbpWeb().AntiForgery.IsEnabled = false; ConfigureSwaggerUi(); }
private void ConfigureSwaggerUi() { Configuration.Modules.AbpWebApi().HttpConfiguration .EnableSwagger(c => { c.SingleApiVersion("v1", "SwaggerIntegrationDemo.WebApi"); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); }) .EnableSwaggerUi(c => { c.InjectJavaScript(Assembly.GetAssembly(typeof(IndustryCloudWebApiModule)), "AbpCompanyName.AbpProjectName.Api.Scripts.Swagger-Custom.js"); }); }
新增js文件
.WebApi\Api\Scripts\Swagger-Custom.js
文件内容参考: