ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\BoxedSoftware.Postgres.csproj
| |
| <Project Sdk="Microsoft.NET.Sdk"> |
| |
| <PropertyGroup> |
| <TargetFramework>net7.0</TargetFramework> |
| <ImplicitUsings>enable</ImplicitUsings> |
| <Nullable>enable</Nullable> |
| <RootNamespace>BoxedSoftware.Postgres</RootNamespace> |
| </PropertyGroup> |
| |
| <ItemGroup> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11"> |
| <PrivateAssets>all</PrivateAssets> |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
| </PackageReference> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.11" /> |
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" /> |
| </ItemGroup> |
| |
| <ItemGroup> |
| <ProjectReference Include="..\..\BoxedSoftware.Models\BoxedSoftware.Models.csproj" /> |
| </ItemGroup> |
| |
| </Project> |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Marker.cs
| |
| namespace BoxedSoftware.Postgres; |
| |
| public abstract class Marker {} |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\BoxedSoftware.Sqlite.csproj
| |
| <Project Sdk="Microsoft.NET.Sdk"> |
| |
| <PropertyGroup> |
| <TargetFramework>net7.0</TargetFramework> |
| <ImplicitUsings>enable</ImplicitUsings> |
| <Nullable>enable</Nullable> |
| </PropertyGroup> |
| |
| <ItemGroup> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11"> |
| <PrivateAssets>all</PrivateAssets> |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
| </PackageReference> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.11" /> |
| </ItemGroup> |
| |
| <ItemGroup> |
| <ProjectReference Include="..\..\BoxedSoftware.Models\BoxedSoftware.Models.csproj" /> |
| </ItemGroup> |
| |
| </Project> |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Marker.cs
| |
| namespace BoxedSoftware.Sqlite; |
| |
| public abstract class Marker {} |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20220719145111_Initial.cs
| |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| |
| public partial class Initial : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.CreateTable( |
| name: "Vehicles", |
| columns: table => new |
| { |
| Id = table.Column<int>(type: "integer", nullable: false) |
| .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), |
| VehicleIdentificationNumber = table.Column<string>(type: "text", nullable: false), |
| Model = table.Column<string>(type: "text", nullable: false), |
| Type = table.Column<string>(type: "text", nullable: false), |
| Fuel = table.Column<string>(type: "text", nullable: false) |
| }, |
| constraints: table => |
| { |
| table.PrimaryKey("PK_Vehicles", x => x.Id); |
| }); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropTable( |
| name: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20220719145111_Initial.Designer.cs
| |
| |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20220719145111_Initial")] |
| partial class Initial |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder |
| .HasAnnotation("ProductVersion", "7.0.0-preview.6.22329.4") |
| .HasAnnotation("Relational:MaxIdentifierLength", 63); |
| |
| NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("integer"); |
| |
| NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20240625113340_add country ps.cs
| |
| using Microsoft.EntityFrameworkCore.Migrations; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| |
| public partial class addcountryps : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.AddColumn<string>( |
| name: "Country", |
| table: "Vehicles", |
| type: "text", |
| nullable: false, |
| defaultValue: ""); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropColumn( |
| name: "Country", |
| table: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20240625113340_add country ps.Designer.cs
| |
| |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20240625113340_add country ps")] |
| partial class addcountryps |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder |
| .HasAnnotation("ProductVersion", "7.0.11") |
| .HasAnnotation("Relational:MaxIdentifierLength", 63); |
| |
| NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("integer"); |
| |
| NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20240625113632_add createat ps.cs
| |
| using System; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| |
| public partial class addcreateatps : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.AddColumn<DateTime>( |
| name: "CreateAt", |
| table: "Vehicles", |
| type: "timestamp with time zone", |
| nullable: false, |
| defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropColumn( |
| name: "CreateAt", |
| table: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\20240625113632_add createat ps.Designer.cs
| |
| |
| using System; |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20240625113632_add createat ps")] |
| partial class addcreateatps |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder |
| .HasAnnotation("ProductVersion", "7.0.11") |
| .HasAnnotation("Relational:MaxIdentifierLength", 63); |
| |
| NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("integer"); |
| |
| NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<DateTime>("CreateAt") |
| .HasColumnType("timestamp with time zone"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Postgres\Migrations\VehiclesContextModelSnapshot.cs
| |
| |
| using System; |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Postgres.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| partial class VehiclesContextModelSnapshot : ModelSnapshot |
| { |
| protected override void BuildModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder |
| .HasAnnotation("ProductVersion", "7.0.11") |
| .HasAnnotation("Relational:MaxIdentifierLength", 63); |
| |
| NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("integer"); |
| |
| NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<DateTime>("CreateAt") |
| .HasColumnType("timestamp with time zone"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("text"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20220719145157_Initial.cs
| |
| using Microsoft.EntityFrameworkCore.Migrations; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| |
| public partial class Initial : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.CreateTable( |
| name: "Vehicles", |
| columns: table => new |
| { |
| Id = table.Column<int>(type: "INTEGER", nullable: false) |
| .Annotation("Sqlite:Autoincrement", true), |
| VehicleIdentificationNumber = table.Column<string>(type: "TEXT", nullable: false), |
| Model = table.Column<string>(type: "TEXT", nullable: false), |
| Type = table.Column<string>(type: "TEXT", nullable: false), |
| Fuel = table.Column<string>(type: "TEXT", nullable: false) |
| }, |
| constraints: table => |
| { |
| table.PrimaryKey("PK_Vehicles", x => x.Id); |
| }); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropTable( |
| name: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20220719145157_Initial.Designer.cs
| |
| |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20220719145157_Initial")] |
| partial class Initial |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder.HasAnnotation("ProductVersion", "7.0.0-preview.6.22329.4"); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("INTEGER"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20240625113240_add country field.cs
| |
| using Microsoft.EntityFrameworkCore.Migrations; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| |
| public partial class addcountryfield : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.AddColumn<string>( |
| name: "Country", |
| table: "Vehicles", |
| type: "TEXT", |
| nullable: false, |
| defaultValue: ""); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropColumn( |
| name: "Country", |
| table: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20240625113240_add country field.Designer.cs
| |
| |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20240625113240_add country field")] |
| partial class addcountryfield |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder.HasAnnotation("ProductVersion", "7.0.11"); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("INTEGER"); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20240625113557_add create field.cs
| |
| using System; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| |
| public partial class addcreatefield : Migration |
| { |
| |
| protected override void Up(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.AddColumn<DateTime>( |
| name: "CreateAt", |
| table: "Vehicles", |
| type: "TEXT", |
| nullable: false, |
| defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); |
| } |
| |
| |
| protected override void Down(MigrationBuilder migrationBuilder) |
| { |
| migrationBuilder.DropColumn( |
| name: "CreateAt", |
| table: "Vehicles"); |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\20240625113557_add create field.Designer.cs
| |
| |
| using System; |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Migrations; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| [Migration("20240625113557_add create field")] |
| partial class addcreatefield |
| { |
| |
| protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder.HasAnnotation("ProductVersion", "7.0.11"); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("INTEGER"); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<DateTime>("CreateAt") |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\Migrations\BoxedSoftware.Sqlite\Migrations\VehiclesContextModelSnapshot.cs
| |
| |
| using System; |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using Microsoft.EntityFrameworkCore.Infrastructure; |
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
| |
| #nullable disable |
| |
| namespace BoxedSoftware.Sqlite.Migrations |
| { |
| [DbContext(typeof(VehiclesContext))] |
| partial class VehiclesContextModelSnapshot : ModelSnapshot |
| { |
| protected override void BuildModel(ModelBuilder modelBuilder) |
| { |
| #pragma warning disable 612, 618 |
| modelBuilder.HasAnnotation("ProductVersion", "7.0.11"); |
| |
| modelBuilder.Entity("BoxedSoftware.Models.Vehicle", b => |
| { |
| b.Property<int>("Id") |
| .ValueGeneratedOnAdd() |
| .HasColumnType("INTEGER"); |
| |
| b.Property<string>("Country") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<DateTime>("CreateAt") |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Fuel") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Model") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("Type") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.Property<string>("VehicleIdentificationNumber") |
| .IsRequired() |
| .HasColumnType("TEXT"); |
| |
| b.HasKey("Id"); |
| |
| b.ToTable("Vehicles"); |
| }); |
| #pragma warning restore 612, 618 |
| } |
| } |
| } |
| |
ef-core-multiple-providers-main\.config\dotnet-tools.json
| |
| { |
| "version": 1, |
| "isRoot": true, |
| "tools": { |
| "dotnet-ef": { |
| "version": "8.0.6", |
| "commands": [ |
| "dotnet-ef" |
| ], |
| "rollForward": false |
| } |
| } |
| } |
ef-core-multiple-providers-main\BoxedSoftware\appsettings.json
| |
| { |
| "Logging": { |
| "LogLevel": { |
| "Default": "Debug", |
| "System": "Information", |
| "Microsoft": "Information" |
| } |
| }, |
| "ConnectionStrings": { |
| "Sqlite" : "Data Source=vehicles.db", |
| "Postgres" : "User ID=postgres;Password=Pass123!;Server=localhost;Port=5432;Database=vehicles;" |
| } |
| } |
ef-core-multiple-providers-main\BoxedSoftware\BoxedSoftware.csproj
| |
| <Project Sdk="Microsoft.NET.Sdk.Web"> |
| |
| <PropertyGroup> |
| <OutputType>Exe</OutputType> |
| <TargetFramework>net7.0</TargetFramework> |
| <ImplicitUsings>enable</ImplicitUsings> |
| <Nullable>enable</Nullable> |
| </PropertyGroup> |
| |
| <ItemGroup> |
| <PackageReference Include="Bogus" Version="34.0.2" /> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11"> |
| <PrivateAssets>all</PrivateAssets> |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
| </PackageReference> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.11" /> |
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" /> |
| </ItemGroup> |
| |
| <ItemGroup> |
| <ProjectReference Include="..\BoxedSoftware.Models\BoxedSoftware.Models.csproj" /> |
| <ProjectReference Include="..\Migrations\BoxedSoftware.Postgres\BoxedSoftware.Postgres.csproj" /> |
| <ProjectReference Include="..\Migrations\BoxedSoftware.Sqlite\BoxedSoftware.Sqlite.csproj" /> |
| </ItemGroup> |
| |
| </Project> |
| |
ef-core-multiple-providers-main\BoxedSoftware\Program.cs
| |
| using BoxedSoftware.Models; |
| using Microsoft.EntityFrameworkCore; |
| using static BoxedSoftware.Provider; |
| |
| var builder = WebApplication.CreateBuilder(args); |
| var config = builder.Configuration; |
| |
| builder.Services.AddDbContext<VehiclesContext>(options => |
| { |
| var provider = config.GetValue("provider", Sqlite.Name); |
| System.Console.WriteLine(provider); |
| |
| if (provider == Sqlite.Name) |
| { |
| options.UseSqlite( |
| config.GetConnectionString(Sqlite.Name)!, |
| x => x.MigrationsAssembly(Sqlite.Assembly) |
| |
| ); |
| } |
| |
| if (provider == Postgres.Name) { |
| options.UseNpgsql( |
| config.GetConnectionString(Postgres.Name)!, |
| x => x.MigrationsAssembly(Postgres.Assembly) |
| ); |
| } |
| }); |
| |
| |
| |
| var app = builder.Build(); |
| |
| |
| |
| using (var scope = app.Services.CreateScope()) { |
| var db = scope.ServiceProvider.GetRequiredService<VehiclesContext>(); |
| await VehiclesContext.InitializeAsync(db); |
| } |
| |
| |
| |
| |
| |
| |
| app.MapGet("/", (VehiclesContext db) => |
| db.Vehicles.OrderBy(x => x.Id).Take(10).ToList() |
| ); |
| |
| app.Run(); |
| |
| |
ef-core-multiple-providers-main\BoxedSoftware\Providers.cs
| |
| namespace BoxedSoftware; |
| |
| public record Provider(string Name, string Assembly) |
| { |
| public static readonly Provider Sqlite = new (nameof(Sqlite), typeof(Sqlite.Marker).Assembly.GetName().Name!); |
| public static readonly Provider Postgres = new (nameof(Postgres), typeof(Postgres.Marker).Assembly.GetName().Name!); |
| } |
| |
ef-core-multiple-providers-main\BoxedSoftware.Models\BoxedSoftware.Models.csproj
| |
| <Project Sdk="Microsoft.NET.Sdk"> |
| |
| <PropertyGroup> |
| <TargetFramework>net7.0</TargetFramework> |
| <ImplicitUsings>enable</ImplicitUsings> |
| <Nullable>enable</Nullable> |
| </PropertyGroup> |
| |
| <ItemGroup> |
| <PackageReference Include="Bogus" Version="34.0.2" /> |
| <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" /> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11"> |
| <PrivateAssets>all</PrivateAssets> |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
| </PackageReference> |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.11" /> |
| </ItemGroup> |
| |
| </Project> |
| |
ef-core-multiple-providers-main\BoxedSoftware.Models\VehiclesContext.cs
| |
| using Bogus; |
| using Microsoft.EntityFrameworkCore; |
| |
| namespace BoxedSoftware.Models; |
| |
| public class VehiclesContext : DbContext |
| { |
| public VehiclesContext(DbContextOptions<VehiclesContext> options) |
| : base(options) |
| { |
| } |
| |
| public DbSet<Vehicle> Vehicles { get; set; } |
| |
| public static async Task InitializeAsync(VehiclesContext db) |
| { |
| await db.Database.MigrateAsync(); |
| |
| |
| if (db.Vehicles.Any()) |
| return; |
| |
| |
| |
| var fake = new Faker<Vehicle>() |
| .Rules((f, v) => v.VehicleIdentificationNumber = f.Vehicle.Vin()) |
| .Rules((f, v) => v.Model = f.Vehicle.Model()) |
| .Rules((f, v) => v.Type = f.Vehicle.Type()) |
| .Rules((f, v) => v.Fuel = f.Vehicle.Fuel()); |
| |
| var vehicles = fake.Generate(100); |
| |
| db.Vehicles.AddRange(vehicles); |
| await db.SaveChangesAsync(); |
| } |
| } |
| |
| public class Vehicle |
| { |
| public int Id { get; set; } |
| public string VehicleIdentificationNumber { get; set; } = ""; |
| public string Model { get; set; } = ""; |
| public string Type { get; set; } = ""; |
| public string Fuel { get; set; } = ""; |
| public string Country { get; set; } = ""; |
| public DateTime CreateAt { get; set; } = DateTime.Now; |
| |
| } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战