QDataLite.Net is a DotNet library that makes the data query more flexible.
For the origin of QDataLite.Net, please refer to this blog post.
It used to be a nightmare when implementing MVC controllers for different kinds of data access requirements. Take the PersonModel
as an example, you may implement different kinds of services such as:
[HttpGet("/genderis/{gender}")]
public async Task<IActionResult> GetPersonsByGender([FromRoute] int gender){}
[HttpGet("/youngerthan/{age}")]
public async Task<IActionResult> GetPersonsYoungerThan([FromRoute] int age){}
[HttpGet("/olderthan/{age}")]
public async Task<IActionResult> GetPersonsOlderThan([FromRoute] int age){}
Luckily, with the help of the QDataLite.Net library, you can make the server-side MVC controller extremely simpler. It is possible to achieve different requirements in only one method, and there are more benefits.
The package was published at nuget gallery: https://www.nuget.org/packages/RoyLab.QData.Lite/
dotnet add package RoyLab.QData.Lite
Take the PersonModel
as an example:
public class PersonModel
{
public Guid Id { get; set; }
public int Age { get; set; }
public int Gender { get; set; }
public string Name { get; set; }
}
To provide the data access service, one function is good enough:
[HttpGet]
[Authorize]
public IActionResult Query([FromQuery] string selector, [FromQuery] string filter,
[FromQuery] string orderBy)
{
var persons = dbContext.Set<PersonModel>()
.QueryDynamic(selector, filter, orderBy);
return Ok(persons);
}
This service enables the client-side flexibility on any kind of data query.
selector
is a list of property names separated by commas (,)filter
is a query expression in the form of Polish NotationorderBy
is a list of property names with prefix + or -, separated by semi-colons (;)
Here are some examples for quick start-up with this powerful library.
For simplicity, the parameters below were not URL-encoded, please remember to encode the values in real web requests
Example 1
get name and age of persons, whose age is equal or older than 18, order by age
/api/person?selector=Name,Age&filter=Age>=18&orderBy=+Age
Example 2: get persons whose name is Roy
/api/person?filter=Name=Roy
Example 3: get males whose age is between [25, 50), order by age in decending order
/api/person?filter=&(&(Age>=25)(Age<50))(Gender=1)&orderBy=-Age
Feel free to report or request at: https://github.com/RoyLab42/QData.Net/issues