Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

A simple query language for Entity Framework Core.

License

NotificationsYou must be signed in to change notification settings

spectresystems/spectre.query

Repository files navigation

NuGetBuild Status

Spectre.Query is a library for doing simplified (safe) querying in Entity Framework Core. Perfect when you want to let end users or APIs search with a SQL-esque language without actually letting them execute any SQL directly (which you never should).

ID > 0 AND Year < 2007 AND Comment != null AND (!Seen OR Comment LIKE '%Awesome%')

This project is currently under active development and might not be ready for production.

Table of Contents

  1. Usage
  2. Usage (ASP.NET Core)
  3. License

Usage

1. Install the NuGet package

PM> Install-Package Spectre.Query

2. Create the query provider

varprovider=QueryProviderBuilder.Build(context, options=>{options.Configure<Movie>(movie=>{movie.Map("Id", e=>e.MovieId);movie.Map("Genre", e=>e.Genre.Name);movie.Map("Title", e=>e.Name);movie.Map("Year", e=>e.ReleasedAt);movie.Map("Score", e=>e.Rating);movie.Map("Seen", e=>e.Seen);});});

The createdIQueryProvider<TContext> is thread safe andcan be cached for the duration of the application.

3. Query the database

varmovies=provider.Query<Movie>(context,"NOT Seen AND Score > 60").ToList();

Usage (ASP.NET Core)

1. Install the NuGet package

PM> Install-Package Spectre.Query.AspNetCore

2. Register the query provider

Start by adding the registrations in yourStartup.cs.

publicvoidConfigureServices(IServiceCollectionservices){services.AddQueryProvider<MovieDbContext>(options=>{options.Configure<Movie>(movie=>{movie.Map("Id", e=>e.MovieId);movie.Map("Genre", e=>e.Genre.Name);movie.Map("Title", e=>e.Name);movie.Map("Year", e=>e.ReleasedAt);movie.Map("Score", e=>e.Rating);movie.Map("Seen", e=>e.Seen);});});// ...}
publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){// This is not required, but will make sure that all// initialization is performed at start up and not at// the first time the query provider is used.app.UseQueryProvider<MovieDbContext>();// ...}

3. Query the database

[ApiController][Route("api/movies")]publicclassMovieController:ControllerBase{privatereadonlyMovieContext_context;privatereadonlyIQueryProvider<MovieContext>_provider;publicMovieController(MovieContextcontext,IQueryProvider<MovieContext>provider){_context=context;_provider=provider;}[HttpGet]publicIActionResult<List<Movie>>Query([FromHeader]stringquery="Rating > 80 AND !Seen"){return_provider.Query<Movie>(_context,query).OrderByDescending(movie=>movie.Rating).ToList()}}

License

Copyright © Spectre Systems

Spectre.Query is provided as-is under the MIT license. For more information seeLICENSE.

About

A simple query language for Entity Framework Core.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp