Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson committed Sep 11, 2018
2 parents eb66651 + 32b5133 commit 5226c79
Show file tree
Hide file tree
Showing 44 changed files with 593 additions and 274 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### New in 0.8.0 (Released 2018/09/11)

- [__#18__](https://github.com/spectresystems/spectre.query/issues/18) Support querying of collections
- [__#21__](https://github.com/spectresystems/spectre.query/issues/21) Can't parse integer/decimal followed by a closing parenthesis

### New in 0.7.0 (Released 2018/08/21)

- [__#4__](https://github.com/spectresystems/spectre.query/issues/4) Add support for LIKE operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public HomeController(MovieContext context, IQueryProvider<MovieContext> provide
public IActionResult Index(string query = null)
{
var movies = _provider.Query<Movie>(_context, query)
.Include(m => m.Genre)
.Include(m => m.Genres).ThenInclude(g => g.Genre)
.OrderByDescending(movie => movie.Rating)
.ToList();

Expand All @@ -37,25 +37,5 @@ public IActionResult Search(SearchResultModel<Movie> model)
{
return RedirectToAction(nameof(Index), new { query = model.Query });
}

[HttpGet]
public IActionResult Projection(string query = null)
{
var movies = _provider.Query<MovieProjection>(_context, query)
.OrderByDescending(x => x.Rating)
.ToList();

return View(new SearchResultModel<MovieProjection>
{
Movies = movies,
Query = query
});
}

[HttpPost]
public IActionResult SearchProjection(SearchResultModel<Movie> model)
{
return RedirectToAction(nameof(Projection), new { query = model.Query });
}
}
}
7 changes: 5 additions & 2 deletions examples/Spectre.Query.Example.AspNetCore/Data/Movie.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Spectre.Query.AspNetCore.Example.Data
using System.Collections.Generic;

namespace Spectre.Query.AspNetCore.Example.Data
{
public sealed class Movie
{
Expand All @@ -7,6 +9,7 @@ public sealed class Movie
public int ReleasedAt { get; set; }
public int Rating { get; set; }
public bool Seen { get; set; }
public Genre Genre { get; set; }

public List<MovieGenre> Genres { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ public sealed class MovieContext : DbContext
public DbSet<Movie> Movies { get; set; }
public DbSet<Genre> Genres { get; set; }

public DbQuery<MovieProjection> Projections { get; set; }

public MovieContext(DbContextOptions<MovieContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Query<MovieProjection>()
.ToView("View_Movies")
.Property(v => v.Genre).HasColumnName("GenreName");
modelBuilder.Entity<MovieGenre>()
.HasKey(t => new { t.MovieId, t.GenreId });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Collections.Generic;
using Spectre.Query.AspNetCore.Example.Data;

namespace Spectre.Query.Example.AspNetCore.Data
{
public static class MovieContextSeeder
{
public static void Seed(MovieContext context)
{
var drama = new Genre { Name = "Drama" };
var crime = new Genre { Name = "Crime" };
var scifi = new Genre { Name = "Sci-Fi" };
var action = new Genre { Name = "Action" };
var comedy = new Genre { Name = "Comedy" };
var thriller = new Genre { Name = "Thriller" };
var family = new Genre { Name = "Family" };
var fantasy = new Genre { Name = "Fantasy" };
var adventure = new Genre { Name = "Adventure" };
var horror = new Genre { Name = "Horror" };
var mystery = new Genre { Name = "Mystery" };
var biography = new Genre { Name = "Biography" };
var romance = new Genre { Name = "Romance" };

var movies = new List<Movie>
{
new Movie { Name = "The Shawshank Redemption", Rating = 93, ReleasedAt = 1994, Seen = true },
new Movie { Name = "The Godfather", Rating = 92, ReleasedAt = 1972, Seen = true },
new Movie { Name = "It's a Wonderful Life", Rating = 86, ReleasedAt = 1946, Seen = false },
new Movie { Name = "Back to the Future", Rating = 85, ReleasedAt = 1985, Seen = true },
new Movie { Name = "Psycho", Rating = 85, ReleasedAt = 1960, Seen = true },
new Movie { Name = "The Fast and the Furious: Tokyo Drift", Rating = 60, ReleasedAt = 2006, Seen = false },
new Movie { Name = "Spider-Man 3", Rating = 62, ReleasedAt = 2007, Seen = false },
new Movie { Name = "Interstellar", Rating = 86, ReleasedAt = 2014, Seen = true },
new Movie { Name = "The Disaster Artist", Rating = 75, ReleasedAt = 2017, Seen = true },
new Movie { Name = "The Room", Rating = 36, ReleasedAt = 2003, Seen = true },
new Movie { Name = "Zoolander", Rating = 66, ReleasedAt = 2001, Seen = true },
new Movie { Name = "The Big Sick", Rating = 76, ReleasedAt = 2017, Seen = false },
new Movie { Name = "Moonlight", Rating = 74, ReleasedAt = 2016, Seen = true },
new Movie { Name = "Get Out", Rating = 77, ReleasedAt = 2017, Seen = false },
new Movie { Name = "Perfetti Sconosciuti", Rating = 78, ReleasedAt = 2016, Seen = true },
new Movie { Name = "Jurassic Park", Rating = 81, ReleasedAt = 1993, Seen = true },
new Movie { Name = "Little Miss Sunshine", Rating = 78, ReleasedAt = 2006, Seen = true },
new Movie { Name = "The Usual Suspects", Rating = 86, ReleasedAt = 1995, Seen = true },
new Movie { Name = "Gremlings", Rating = 72, ReleasedAt = 1984, Seen = true },
new Movie { Name = "Stuart Little", Rating = 59, ReleasedAt = 1999, Seen = false },
new Movie { Name = "Cars 2", Rating = 62, ReleasedAt = 2011, Seen = false },
new Movie { Name = "Zombieland", Rating = 77, ReleasedAt = 2009, Seen = true },
new Movie { Name = "The Pursuit of Happyness", Rating = 80, ReleasedAt = 2006, Seen = false },
new Movie { Name = "Fargo", Rating = 81, ReleasedAt = 1996, Seen = true }
};

context.Movies.AddRange(movies);
context.Genres.AddRange(
drama, crime, scifi, action, comedy, thriller, family,
fantasy, adventure, horror, mystery, biography, romance);

context.ConnectTags(
(movies[0], new[] { drama }),
(movies[1], new[] { crime }),
(movies[2], new[] { drama, family, fantasy }),
(movies[3], new[] { adventure, drama, scifi }),
(movies[4], new[] { horror, mystery, thriller }),
(movies[5], new[] { action, crime, thriller }),
(movies[6], new[] { action, adventure, scifi }),
(movies[7], new[] { adventure, drama, scifi }),
(movies[8], new[] { biography, comedy, drama }),
(movies[9], new[] { drama }),
(movies[10], new[] { comedy }),
(movies[11], new[] { comedy, drama, romance }),
(movies[12], new[] { drama }),
(movies[13], new[] { horror, mystery, thriller }),
(movies[14], new[] { comedy, drama }),
(movies[15], new[] { adventure, scifi, thriller }),
(movies[16], new[] { comedy, drama }),
(movies[17], new[] { crime, mystery, thriller }),
(movies[18], new[] { comedy, fantasy, horror }),
(movies[19], new[] { adventure, comedy, family }),
(movies[20], new[] { family, adventure, comedy }),
(movies[21], new[] { adventure, comedy, horror }),
(movies[22], new[] { biography, drama }),
(movies[23], new[] { crime, drama, thriller }));

context.SaveChanges();
}

public static void ConnectTags(this MovieContext context, params (Movie document, Genre[] genres)[] items)
{
foreach (var (movie, genres) in items)
{
foreach (var genre in genres)
{
context.Add(new MovieGenre { Movie = movie, Genre = genre });
}
}
}
}
}
11 changes: 11 additions & 0 deletions examples/Spectre.Query.Example.AspNetCore/Data/MovieGenre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Spectre.Query.AspNetCore.Example.Data
{
public sealed class MovieGenre
{
public int MovieId { get; set; }
public Movie Movie { get; set; }

public int GenreId { get; set; }
public Genre Genre { get; set; }
}
}
12 changes: 0 additions & 12 deletions examples/Spectre.Query.Example.AspNetCore/Data/MovieProjection.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,53 @@ protected override void Up(MigrationBuilder migrationBuilder)
Name = table.Column<string>(nullable: true),
ReleasedAt = table.Column<int>(nullable: false),
Rating = table.Column<int>(nullable: false),
Seen = table.Column<bool>(nullable: false),
GenreId = table.Column<int>(nullable: true)
Seen = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Movies", x => x.MovieId);
});

migrationBuilder.CreateTable(
name: "MovieGenre",
columns: table => new
{
MovieId = table.Column<int>(nullable: false),
GenreId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MovieGenre", x => new { x.MovieId, x.GenreId });
table.ForeignKey(
name: "FK_Movies_Genres_GenreId",
name: "FK_MovieGenre_Genres_GenreId",
column: x => x.GenreId,
principalTable: "Genres",
principalColumn: "GenreId",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MovieGenre_Movies_MovieId",
column: x => x.MovieId,
principalTable: "Movies",
principalColumn: "MovieId",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Movies_GenreId",
table: "Movies",
name: "IX_MovieGenre_GenreId",
table: "MovieGenre",
column: "GenreId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Movies");
name: "MovieGenre");

migrationBuilder.DropTable(
name: "Genres");

migrationBuilder.DropTable(
name: "Movies");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -38,8 +37,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<int?>("GenreId");

b.Property<string>("Name");

b.Property<int>("Rating");
Expand All @@ -50,16 +47,33 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("MovieId");

b.ToTable("Movies");
});

modelBuilder.Entity("Spectre.Query.AspNetCore.Example.Data.MovieGenre", b =>
{
b.Property<int>("MovieId");

b.Property<int>("GenreId");

b.HasKey("MovieId", "GenreId");

b.HasIndex("GenreId");

b.ToTable("Movies");
b.ToTable("MovieGenre");
});

modelBuilder.Entity("Spectre.Query.AspNetCore.Example.Data.Movie", b =>
modelBuilder.Entity("Spectre.Query.AspNetCore.Example.Data.MovieGenre", b =>
{
b.HasOne("Spectre.Query.AspNetCore.Example.Data.Genre", "Genre")
.WithMany()
.HasForeignKey("GenreId");
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade);

b.HasOne("Spectre.Query.AspNetCore.Example.Data.Movie", "Movie")
.WithMany("Genres")
.HasForeignKey("MovieId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
Expand Down
Loading

0 comments on commit 5226c79

Please sign in to comment.