Created
February 13, 2025 05:12
-
-
Save shreyans-padmani/6c1820839388abc98eef7eb8e20dc04f to your computer and use it in GitHub Desktop.
This Gist contains configuration and setup files for a .NET 8.0 web application using Entity Framework Core with PostgreSQL. It includes: Project.sh: A shell script to: Add necessary NuGet packages for Entity Framework Core, PostgreSQL, and code generation. Scaffold the database context and models from an existing PostgreSQL database. Install th…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Project.sh | |
dotnet add package Microsoft.EntityFrameworkCore.Design | |
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL | |
dotnet ef dbcontext scaffold "Host=localhost;Database=Organization;Username=postgres;Password=1234" Npgsql.EntityFrameworkCore.PostgreSQL -o Models | |
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design | |
dotnet add package Microsoft.EntityFrameworkCore.SqlServer | |
dotnet tool install --global dotnet-aspnet-codegenerator | |
dotnet aspnet-codegenerator --help | |
dotnet add package Microsoft.EntityFrameworkCore.Tools | |
dotnet aspnet-codegenerator controller -name MstGallaryController -m MstGallary -dc OrganizationContext --relativeFolderPath Controllers --useDefaultLayout | |
appsettings.json | |
"ConnectionStrings": { | |
"DefaultConnection": "Host=localhost;Database=Organization;Username=postgres;Password=1936" | |
}, | |
Program.cs | |
builder.Services.AddDbContext<OrganizationContext>(options => | |
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); | |
Project.csproj | |
<Project Sdk="Microsoft.NET.Sdk.Web"> | |
<PropertyGroup> | |
<TargetFramework>net8.0</TargetFramework> | |
<Nullable>enable</Nullable> | |
<ImplicitUsings>enable</ImplicitUsings> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2"> | |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
<PrivateAssets>all</PrivateAssets> | |
</PackageReference> | |
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" /> | |
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2"> | |
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
<PrivateAssets>all</PrivateAssets> | |
</PackageReference> | |
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" /> | |
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment