User Tools

Site Tools


sqlite_dotnet_ef_vscode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
sqlite_dotnet_ef_vscode [2021/09/22 05:20]
sausage [Creating a .NET Core application with Entity Framework and SQLite in VSCode]
sqlite_dotnet_ef_vscode [2021/09/22 05:29]
sausage
Line 22: Line 22:
 Create the project by typing the following into the terminal: Create the project by typing the following into the terminal:
  
-  dotnet ​core mvc+  dotnet ​new mvc
  
 Your project has been created, but cannot be debugged yet without the debug extension being loaded. ​ Your project has been created, but cannot be debugged yet without the debug extension being loaded. ​
Line 96: Line 96:
 namespace SQLiteLab namespace SQLiteLab
 { {
-    public class SqliteDbContext : DbContext {+    public class SqliteDbContext : DbContext 
 +    ​{
  
         //entities representing tables in the database         //entities representing tables in the database
Line 156: Line 157:
 ===== Producing the database ===== ===== Producing the database =====
  
-To make the database, we need to add a "​migration"​ and then perform a database update that will use that migration. So what's a migration? It's either the information to make the whole database ​je first time, or incremental changes to a database schema. It allows you to change your database schema over time.+To make the database, we need to add a "​migration"​ and then perform a database update that will use that migration. So what's a migration? It's either the information to make the whole database ​the first time, or incremental changes to a database schema. It allows you to change your database schema over time.
  
 To make a migration, you need the ''​Microsoft.EntityFrameworkCore.Design''​ package. Again, use the search at nuget.org to get the correct .NET CLI command to use. In my case, for .NET 5 it was: To make a migration, you need the ''​Microsoft.EntityFrameworkCore.Design''​ package. Again, use the search at nuget.org to get the correct .NET CLI command to use. In my case, for .NET 5 it was:
Line 222: Line 223:
  
 <code c> <code c>
- private void CreateGuidRecords() +private void CreateGuidRecords() 
-+
- _context.GuidInfos.Add(new GuidInfo { +    _context.GuidInfos.Add(new GuidInfo { 
- Guid = new Guid("​D06FACE5-CA6E-D1CE-FAD5-D0661E555555"​),​ +        Guid = new Guid("​D06FACE5-CA6E-D1CE-FAD5-D0661E555555"​),​ 
- Feature = "Has dogs, cages, dices and dog faces."​ +        Feature = "Has dogs, cages, dices and dog faces."​ 
- });+    });
  
- _context.GuidInfos.Add(new GuidInfo { +    ​_context.GuidInfos.Add(new GuidInfo { 
- Guid = new Guid("​01101101-0110-0001-0111-010001100101"​),​ +        Guid = new Guid("​01101101-0110-0001-0111-010001100101"​),​ 
- Feature = "MATE in binary. Good to have your mates."​ +        Feature = "MATE in binary. Good to have your mates."​ 
- }); +    }); 
-  +     
-        _context.SaveChanges();​ +    _context.SaveChanges();​ 
-  +}
- }+
 </​code>​ </​code>​
  
Line 242: Line 242:
  
 <code c> <code c>
- public IActionResult Index() +    ​public IActionResult Index() 
-+    
- CreateGuidRecords();​ +        CreateGuidRecords();​ 
- return View(); +        return View(); 
- }+    }
 </​code>​ </​code>​
  
sqlite_dotnet_ef_vscode.txt · Last modified: 2021/09/22 05:39 by sausage