mirror of https://github.com/abpframework/abp.git
12 changed files with 277 additions and 18 deletions
@ -0,0 +1,37 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using AbpPerfTest.WithoutAbp.Dtos; |
|||
using AbpPerfTest.WithoutAbp.EntityFramework; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.EntityFrameworkCore; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Controllers |
|||
{ |
|||
[Route("api/books")] |
|||
public class BookController : Controller |
|||
{ |
|||
private readonly BookDbContext _bookDbContext; |
|||
|
|||
public BookController(BookDbContext bookDbContext) |
|||
{ |
|||
_bookDbContext = bookDbContext; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public async Task<List<BookDto>> GetListAsync() |
|||
{ |
|||
var books = await _bookDbContext.Books.ToListAsync(); |
|||
|
|||
return books |
|||
.Select(b => new BookDto |
|||
{ |
|||
Id = b.Id, |
|||
Name = b.Name, |
|||
Price = b.Price, |
|||
IsAvailable = b.IsAvailable |
|||
}) |
|||
.ToList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Dtos |
|||
{ |
|||
public class BookDto |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public float Price { get; set; } |
|||
|
|||
public bool IsAvailable { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Entities |
|||
{ |
|||
public class Book |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public float Price { get; set; } |
|||
|
|||
public bool IsAvailable { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using AbpPerfTest.WithoutAbp.Entities; |
|||
using Microsoft.EntityFrameworkCore; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.EntityFramework |
|||
{ |
|||
public class BookDbContext : DbContext |
|||
{ |
|||
public DbSet<Book> Books { get; set; } |
|||
|
|||
public BookDbContext(DbContextOptions<BookDbContext> builderOptions) |
|||
: base(builderOptions) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|||
{ |
|||
base.OnModelCreating(modelBuilder); |
|||
|
|||
modelBuilder.Entity<Book>(b => |
|||
{ |
|||
b.ToTable("Books"); |
|||
b.Property(x => x.Name).HasMaxLength(128); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System.IO; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
using Microsoft.Extensions.Configuration; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.EntityFramework |
|||
{ |
|||
public class BookDbContextFactory : IDesignTimeDbContextFactory<BookDbContext> |
|||
{ |
|||
public BookDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var configuration = BuildConfiguration(); |
|||
|
|||
var builder = new DbContextOptionsBuilder<BookDbContext>() |
|||
.UseSqlServer(configuration.GetConnectionString("Default")); |
|||
|
|||
return new BookDbContext(builder.Options); |
|||
} |
|||
|
|||
private static IConfigurationRoot BuildConfiguration() |
|||
{ |
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(Directory.GetCurrentDirectory()) |
|||
.AddJsonFile("appsettings.json", optional: false); |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using AbpPerfTest.WithoutAbp.EntityFramework; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Migrations |
|||
{ |
|||
[DbContext(typeof(BookDbContext))] |
|||
[Migration("20201222132615_Added_Books")] |
|||
partial class Added_Books |
|||
{ |
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.UseIdentityColumns() |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 128) |
|||
.HasAnnotation("ProductVersion", "5.0.1"); |
|||
|
|||
modelBuilder.Entity("AbpPerfTest.WithoutAbp.Entities.Book", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<bool>("IsAvailable") |
|||
.HasColumnType("bit"); |
|||
|
|||
b.Property<string>("Name") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("nvarchar(128)"); |
|||
|
|||
b.Property<float>("Price") |
|||
.HasColumnType("real"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("Books"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Migrations |
|||
{ |
|||
public partial class Added_Books : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "Books", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true), |
|||
Price = table.Column<float>(type: "real", nullable: false), |
|||
IsAvailable = table.Column<bool>(type: "bit", nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_Books", x => x.Id); |
|||
}); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "Books"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using AbpPerfTest.WithoutAbp.EntityFramework; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
|
|||
namespace AbpPerfTest.WithoutAbp.Migrations |
|||
{ |
|||
[DbContext(typeof(BookDbContext))] |
|||
partial class BookDbContextModelSnapshot : ModelSnapshot |
|||
{ |
|||
protected override void BuildModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.UseIdentityColumns() |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 128) |
|||
.HasAnnotation("ProductVersion", "5.0.1"); |
|||
|
|||
modelBuilder.Entity("AbpPerfTest.WithoutAbp.Entities.Book", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<bool>("IsAvailable") |
|||
.HasColumnType("bit"); |
|||
|
|||
b.Property<string>("Name") |
|||
.HasMaxLength(128) |
|||
.HasColumnType("nvarchar(128)"); |
|||
|
|||
b.Property<float>("Price") |
|||
.HasColumnType("real"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("Books"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue