====== Entity Framework ====== ===== Model Generation ===== Instructions are for .NET 7 ==== MySQL ==== dotnet new console –o applicationName cd applicationName dotnet add package MySql.EntityFrameworkCore --version 7.0.2 dotnet add package Microsoft.EntityFrameworkCore.Tools --version 7.0.14 If the Entity Framework tool is not already installed: dotnet tool install --global dotnet-ef --version 7.* Then, generate the model files in the models directory: dotnet ef dbcontext scaffold "server=127.0.0.1;port=3306;uid=jimc;pwd=password;database=database_name" MySql.EntityFrameworkCore -o models -f ==== SQL Server ==== dotnet new console –o applicationName cd applicationName dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 7.0.14 dotnet add package Microsoft.EntityFrameworkCore.Tools --version 7.0.14 If the Entity Framework tool is not already installed: dotnet tool install --global dotnet-ef --version 7.* Then, generate the model files in the models directory: dotnet ef dbcontext scaffold "Server=server_ip_address;User Id=sa;Password=password;Database=database_name;Encrypt = No" Microsoft.EntityFrameworkCore.SqlServer -o models -f ===== More Info ===== [[https://learn.microsoft.com/en-us/ef/core/|Entity Framework Core]] [[https://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first.aspx|Data Annotations - Column Attribute in EF 6 & EF Core]] [[https://learn.microsoft.com/en-us/ef/ef6/querying/|Querying and Finding Entities]] {{tag>dotnet database}}