AutoQuery / Ormlite-servicestack: Can I filter out soft deletes on a QueryDb class?

一曲冷凌霜 提交于 2020-01-05 03:56:11

问题


We have a few services built up with Ormlite/Servicestack and we are mostly pulling out database objects and POCOs using QueryData with custom logic.

However, we have one table that really doesn't need to be logically expanded on and works just fine querying the DB directly from the front end using AutoQuery and URL params. However, this table contains an isDeleted column to track soft deletes. The front end should not have any soft-deleted items, and we believe the front end shouldn't be able to get these records (i.e. shouldn't be responsible for querying the API with a ?&isDeleted=false).

So, given our current setup:

[Route("/query/thing/stuff", HttpMethods.Get)]
public class secret_table: QueryDb<secret_table>
{
}

...would it be possible to implement a filter for the QueryDb<> to automatically exclude records where isDeleted=true? And would this be able to be applied only to this table/class?

I'm setting milk and cookies out in hopes that mythz drops by and leaves a present...but any help is appreciated, of course!


回答1:


Have you tried using one of the different extensibility options?

You should also be able to use OrmLite's Select Filter to enable Soft Deletes, e.g:

SqlExpression<secret_table>.SelectFilter = q => q.Where(x => x.IsDeleted != true);

Note your AutoQuery DTO shouldn't reuse the name of the Table as the name of the DTO, use a different name like:

[Route("/query/thing/stuff", HttpMethods.Get)]
public class QuerySecretTable: QueryDb<secret_table> {}


来源:https://stackoverflow.com/questions/45494993/autoquery-ormlite-servicestack-can-i-filter-out-soft-deletes-on-a-querydb-cla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!