Conceptasp.net Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as web apps, IoT apps and mobile backends. ASP.NET Core apps can run on .NET Core or on the full .NET Framework.ASP.NET Core: 新的支持云開發的跨平臺,開源框架。可用來開發web app, 物聯網, 手機后端Source: GitHub Install: VS2015Steps:1, check connectionstringappsettings.json{ "ConnectionStrings": { "DefaultConnection":"Server=(localdb)//mssqllocaldb;Database=ContosoUniversity2;Trusted_Connection=True;MultipleActiveResultSets=true" } 2, add/del fieldModels: add/del PRopertyMvc/Views: add/del show field 3, DB MigrationA, SolutionExplorer/right-click the project/Open in File Explorer B, Hold down theShift key/right-click the project/Open command window hereC, dotnet ef migrations add [RMProductName] -c [Context name]D, dotnet ef database update Get: Data/Migrations/20170217100804_RMProductName.cs and Snapshot modifies by VS 小結: A, Problem: There is already an object named 'CertificationKinds' in the database.原因:__EFMigrationsHistory內沒有數據,VS就認為此時數據庫內沒有表,會自動根據Migrations文件夾內的遷移文件創建表結構。此時數據庫內如果已經存在表CertificationKinds,就會產生報錯。解決:1,dotnet ef migrations add name :直接用修改過表結構的代碼(根據:Model內對應的類),VS會根據遷移文件自動在__EFMigrationsHistory創建修改記錄。 dotnet ef database update :根據遷移文件更新本地數據庫及表 __EFMigrationsHistory 2,dotnet ef database update: 根據之前的遷移文件更新本地數據庫及表 __EFMigrationsHistory dotnet ef migrations add name: 根據新的Model類產生遷移文件 dotnet ef database update: 根據遷移文件更新本地數據庫及表__EFMigrationsHistory B, VS通過文件控制數據庫修改Data:數據庫Migrations:遷移文件夾,存放數據庫遷移文件遷移文件:20170217100804_RMProductName.cs數據庫表結構修改記錄,VS通過這些文件進行數據庫表結構控制xxxxModelSnapShot:AzureGalleryDbContextModelSnapshot.cs數據快照,數據庫對象明細xxxxContext:AzureGalleryDbContext.csModels:存放表結構對應的類文件,VS由此創建數據庫和遷移文件
新聞熱點
疑難解答