Harbin.DataAccess icon indicating copy to clipboard operation
Harbin.DataAccess copied to clipboard

Query by Sample

Open abbasl7 opened this issue 5 years ago • 4 comments

First, thanks for putting things together to make life easy for someone new to Dapper world. Can we query data based on a sample object?

On a side-note, may I know the reason for going with Dapper.FastCRUD than Dapper.SimpleCRUD? Asking because, FastCRUD doesn't seem to be actively maintained

abbasl7 avatar Jan 06 '21 11:01 abbasl7

You mean passing an anonymous object and converting it into dynamic filters? I think it's a nice idea. Maybe it fits better in this other project DapperQueryBuilder, which is embedded inside Harbin.DataAccess. Feel free to submit a PR if you want. Basically in Harbin.DataAccess I just have facade methods which invoke DapperQueryBuilder.

Regarding FastCRUD, I've picked it because it support getting values back from the database (calculated properties), and I frequently use calculated properties (default values) in my databases. As far as I checked SimpleCRUD didn't support this. But I have plans to create a POCO Generator which would automatically set those default values in the entities, and therefore we could replace FastCRUD by SimpleCRUD (which I think is more solid, indeed).

Drizin avatar Jan 06 '21 15:01 Drizin

Not an anonymous object, but a strongly typed object. Let us say I pass an Employee object to a method in EmployeeService class. It will serve as sample to build where clauses internally based on set values of the sample object and return the filtered data.

abbasl7 avatar Jan 07 '21 10:01 abbasl7

I think the issue with passing real entities is that non-nullable properties would always be converted into filters. Let's say I have an entity Person with a property CreatedDate (non-nullable). If we pass .Query(new Person() { LastName="Drizin" }), the CreatedDate would automatically assume a non-null value (DateTime.MinDate), and it would be converted into a where condition. Do you know how other ORMs/libraries (that allow querying by sample object) solve this issue?

Drizin avatar Jan 07 '21 12:01 Drizin

@abbasl7 I've created a fork Harbin.DataAccess.SimpleCRUD using SimpleCRUD instead of FastCRUD. Would you like to give it a try?

Drizin avatar Aug 14 '21 14:08 Drizin