Last active
June 2, 2021 06:15
-
-
Save Layoric/522d867ba7064d0732544de79088f746 to your computer and use it in GitHub Desktop.
autoquery-custom
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
// Connect your database | |
container.AddSingleton<IDbConnectionFactory>(c => | |
new OrmLiteConnectionFactory(MapProjectPath("~/northwind.sqlite"), SqliteDialect.Provider)); | |
// Add the AutoQuery Plugin | |
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 }); |
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
// Return CustomRockstar result to control what the service returns | |
// Join with other tables | |
[Route("/rockstar-albums")] | |
public class QueryRockstarAlbums | |
: QueryDb<Rockstar,CustomRockstar>, IJoin<Rockstar,RockstarAlbum> | |
{ | |
public int? Age { get; set; } | |
public string RockstarAlbumName { get; set; } | |
} | |
// Custom result | |
public class CustomRockstar | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public int? Age { get; set; } | |
// Comes from joined table | |
public string RockstarAlbumName { get; set; } | |
} | |
// Override with custom implementation | |
public class MyQueryServices : Service | |
{ | |
public IAutoQueryDb AutoQuery { get; set; } | |
public async Task<object> Any(QueryRockstarAlbums query) | |
{ | |
using var db = AutoQuery.GetDb(query, base.Request); | |
var q = AutoQuery.CreateQuery(query, base.Request, db); | |
return await AutoQuery | |
.ExecuteAsync(query, q, base.Request, db); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment