Skip to content

Commit

Permalink
Add repro for #1224
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Dec 8, 2022
1 parent 008bc00 commit cde883f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace JsonApiDotNetCoreExample.Data;
public sealed class AppDbContext : DbContext
{
public DbSet<TodoItem> TodoItems => Set<TodoItem>();
public DbSet<PostIt> PostIts => Set<PostIt>();

public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
Expand Down
25 changes: 25 additions & 0 deletions src/Examples/JsonApiDotNetCoreExample/Models/PostIt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace JsonApiDotNetCoreExample.Models;

[Resource]
public class PostIt : Identifiable<int>
{
[Attr]
[Required]
public bool Actif { get; set; }

[Attr]
[Required]
public DateTime Date { get; set; }

[Attr]
[MaxLength(2, ErrorMessage = "Error")]
public string Message { get; set; }

[Attr]
[Required]
public string RefOperateur { get; set; }
}
16 changes: 16 additions & 0 deletions src/Examples/JsonApiDotNetCoreExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Diagnostics;
using JsonApiDotNetCoreExample.Data;
using JsonApiDotNetCoreExample.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand Down Expand Up @@ -98,5 +99,20 @@ static async Task CreateDatabaseAsync(IServiceProvider serviceProvider)
await using AsyncServiceScope scope = serviceProvider.CreateAsyncScope();

var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();

await dbContext.Database.EnsureDeletedAsync();
await dbContext.Database.EnsureCreatedAsync();

var postIt = new PostIt
{
Id = 835405,
Actif = true,
Date = DateTime.UtcNow,
Message = "ab",
RefOperateur = "some-ref"
};

dbContext.PostIts.Add(postIt);

await dbContext.SaveChangesAsync();
}

0 comments on commit cde883f

Please sign in to comment.