Created
August 16, 2021 22:56
-
-
Save adrianhall/0acfe6ac2f9eeedfa768bd3cfba215a7 to your computer and use it in GitHub Desktop.
ASP.NET 6 CRUDL in 40 lines of code
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
using Microsoft.AspNetCore.Datasync; | |
using Microsoft.AspNetCore.Datasync.EFCore; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.EntityFrameworkCore; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); | |
builder.Services.AddDatasyncControllers(); | |
var app = builder.Build(); | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.MapControllers(); | |
app.Run(); | |
public class TodoItem : EntityTableData | |
{ | |
public string? Text { get; set; } | |
public bool IsDeleted { get; set; } | |
} | |
public class AppDbContext : DbContext | |
{ | |
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { } | |
public DbSet<TodoItem> TodoItems => Set<TodoItem>(); | |
} | |
[Route("tables/[controller]")] | |
public class TodoItemController : TableController<TodoItem> | |
{ | |
public TodoItemController(AppDbContext context) | |
{ | |
Repository = new EntityTableRepository<TodoItem>(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment