Giter Site home page Giter Site logo

Comments (6)

JonathanMagnan avatar JonathanMagnan commented on July 28, 2024 1

Hello @cupper1 ,

You currently have the OldValue and NewValue.

So, for this one, you will have to make a filter on your side.

Something like this:

auditEntries.ForEach(x => x.Values = x.Values.Where(y => y.OldValue.ToString() != y.NewValue.ToString()).ToList());

Let me know if that works on your side.

Best Regards,

Jon

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on July 28, 2024

Hello @cupper1 ,

The BulkMerge inserts data that doesn't exist and updates those that already exist.

So it's expected that 500 rows will be returned on the second run as 500 rows have been updated (already existing).

However, there is 2 small errors in your code:

Perhaps you were looking more for a BulkInsert with the InsertIfNotExists option?

NOTE: The Xmin is an internal column in PostgreSQL.

Let me know if I answered correctly your question

Best Regards,

Jon

from dapper-plus.

cupper1 avatar cupper1 commented on July 28, 2024

Hi @JonathanMagnan Thanks for the response, a follow up:
so, on the second run, where all the data is exactly the same, no data was actually updated, so I would have expected the audit log to show 0 entries, as nothing was changed.

Maybe I am going down the wrong path, and is best to explain the use case:

I get the file every day, it has 500 (or 15k) rows in it, almost all the data is exactly the same. Right now I query the database for each row, bring it back, check it against the row in the file and if there is a difference, I update it, if not I move the the next row.

I was expecting that is what this would do for me, and give me an audit log of any rows that have changed. Is this capable of that?

for example, 500 rows from the exact same file has no changes, so audit log would show 0 rows.
tomorrow 1 row is updated with a new firstname, so audit log shows 1 rows, oldvalue / newvalue

if not, is there a way of filtering the audit log where oldvalue !=newvalue ?

Thank you again for the response, I am hoping this product will do this as its much faster than 1 by 1 :)

from dapper-plus.

JonathanMagnan avatar JonathanMagnan commented on July 28, 2024

Hello @cupper1 ,

If I understand your scenario, we indeed support it. You can use either the option MergeMatchedAndOneNotConditionExpression or IgnoreOnMergeMatchedAndOneNotConditionExpression to achieve this behavior. You can learn more about those option here (Documentation is about Entity Framework Extensions but it's the same behavior for Dapper Plus)

See the following online Fiddle: https://dotnetfiddle.net/3lyezo

DapperPlusManager.Entity<Patient>("MergeMatchedAndOneNot").Identity(x => x.PatientID)
	.UseBulkOptions(options => {
		// Use this line if you want to specify all properties. One of them must be different for the "Update" part to be executed
		//options.MergeMatchedAndOneNotConditionExpression = x => new { x.Name, x.Description };
		
		// Use this line if you want to include all properties by default (we specify the key as you can always skip this one, will never be different)
		options.IgnoreOnMergeMatchedAndOneNotConditionExpression = x => new { x.PatientID };
	});

You will notice on my Fiddle:

  • I used a mapper key as I don't want this behavior to be the default behavior when I save a Patient
  • I added the audit in the UseBulkOptions in the connection instead. So I can separate the global mapping from his custom logic
  • I used the mapper key previously created to specify to the BulkMerge to use this mapping

As you can see in the result:

  • On the first run, 2 audit entries has been returned (2 rows inserted)
  • On the second run, 0 audit entry has been returned (nothing has been updated since nothing is different)
  • On the third run, 1 audit entry has been returned as I modified the description for 1 row

Let me know if that's what you were looking for.

Best Regards,

Jon

from dapper-plus.

cupper1 avatar cupper1 commented on July 28, 2024

Hi @JonathanMagnan

THANK YOU! yes this is (almost) exactly what I am looking for! and it works great, I just would like to ask one more question. In the example, the auditentries shows 1 row, but all fields still. So for instance if my schema had 10 columns, and only one changed, it returns all 10 columns with old/new fields. I am just curious if you have another magic option to only return the fields that changed instead?

Thank you again for this!

from dapper-plus.

cupper1 avatar cupper1 commented on July 28, 2024

Thank you again @JonathanMagnan really appreciate you!

from dapper-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.