Skip to content

Confirm that v4.0.0-alpha5 does not have the include bug #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions JsonApiDotnetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GettingStarted", "src\Examp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "test\IntegrationTests\IntegrationTests.csproj", "{CEB08B86-6BF1-4227-B20F-45AE9C1CC6D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "src\Examples\IncludeBug\Test.csproj", "{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -185,6 +187,18 @@ Global
{CEB08B86-6BF1-4227-B20F-45AE9C1CC6D9}.Release|x64.Build.0 = Release|Any CPU
{CEB08B86-6BF1-4227-B20F-45AE9C1CC6D9}.Release|x86.ActiveCfg = Release|Any CPU
{CEB08B86-6BF1-4227-B20F-45AE9C1CC6D9}.Release|x86.Build.0 = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|x64.ActiveCfg = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|x64.Build.0 = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|x86.ActiveCfg = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Debug|x86.Build.0 = Debug|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|Any CPU.Build.0 = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|x64.ActiveCfg = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|x64.Build.0 = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|x86.ActiveCfg = Release|Any CPU
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -201,6 +215,7 @@ Global
{8BCFF95F-4850-427C-AEDB-B5B4F62B2C7B} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
{21D27239-138D-4604-8E49-DCBE41BCE4C8} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
{CEB08B86-6BF1-4227-B20F-45AE9C1CC6D9} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
{53A3C8C1-E7B5-4855-BE93-EF555F65CB46} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}
Expand Down
21 changes: 21 additions & 0 deletions src/Examples/IncludeBug/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;

namespace Test
{
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options) { }

public DbSet<Person> People { get; set; }
public DbSet<Book> Books { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<BookPerson>()
.HasKey(bookPerson => new { bookPerson.BookId, bookPerson.PersonId });
}
}
}
17 changes: 17 additions & 0 deletions src/Examples/IncludeBug/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JsonApiDotNetCore.Models;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Test
{
public class Book : Identifiable
{
[Attr]
public string Title { get; set; }

[NotMapped]
[HasManyThrough(nameof(BookPeople))]
public List<Person> People { get; set; }
public virtual List<BookPerson> BookPeople { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/Examples/IncludeBug/BookPerson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Test
{
public class BookPerson
{
public int BookId { get; set; }
[ForeignKey("BookId")]
public virtual Book Book { get; set; }

public int PersonId { get; set; }
[ForeignKey("PersonId")]
public virtual Person Person { get; set; }
}
}
17 changes: 17 additions & 0 deletions src/Examples/IncludeBug/BooksController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace Test
{
public class BooksController : JsonApiController<Book>
{
public BooksController(
IJsonApiOptions options,
ILoggerFactory loggerFactory,
IResourceService<Book> resourceService)
: base(options, loggerFactory, resourceService)
{ }
}
}
17 changes: 17 additions & 0 deletions src/Examples/IncludeBug/PeopleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace Test
{
public class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiOptions options,
ILoggerFactory loggerFactory,
IResourceService<Person> resourceService)
: base(options, loggerFactory, resourceService)
{ }
}
}
17 changes: 17 additions & 0 deletions src/Examples/IncludeBug/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using JsonApiDotNetCore.Models;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Test
{
public class Person : Identifiable
{
[Attr]
public string Name { get; set; }

[NotMapped]
[HasManyThrough(nameof(BookPeople))]
public List<Book> Books { get; set; }
public virtual List<BookPerson> BookPeople { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Examples/IncludeBug/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Test
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
27 changes: 27 additions & 0 deletions src/Examples/IncludeBug/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54652/",
"sslPort": 44385
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Test": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
73 changes: 73 additions & 0 deletions src/Examples/IncludeBug/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add the Entity Framework Core DbContext like you normally would
services.AddDbContext<AppDbContext>(options =>
{
// Use whatever provider you want, this is just an example
options.UseSqlServer("Data Source=.\\SQLEXPRESS;Initial Catalog=testDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite");
});

// Add JsonApiDotNetCore
services.AddJsonApi<AppDbContext>();
}

public void Configure(IApplicationBuilder app, AppDbContext appDbContext)
{
appDbContext.Database.EnsureCreated();
if (!appDbContext.People.Any())
{
var person1 = new Person
{
Name = "John Doe"
};
var person2 = new Person
{
Name = "Alan Thrall"
};
var book1 = new Book
{
Title = "Explode"
};
var book2 = new Book
{
Title = "Blastoise"
};
var bookPerson1 = new BookPerson
{
Book = book1,
Person = person1
};
var bookPerson2 = new BookPerson
{
Book = book2,
Person = person2
};
var bookPerson3 = new BookPerson
{
Book = book1,
Person = person2
};
person1.BookPeople = new List<BookPerson> { bookPerson1 };
person2.BookPeople = new List<BookPerson> { bookPerson2, bookPerson3 };
appDbContext.People.Add(person1);
appDbContext.People.Add(person2);
appDbContext.Books.Add(book1);
appDbContext.Books.Add(book2);
appDbContext.SaveChanges();
}
app.UseJsonApi();
}
}
}
15 changes: 15 additions & 0 deletions src/Examples/IncludeBug/Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Examples/IncludeBug/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions src/Examples/IncludeBug/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}