Comments (6)
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.
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:
- The
InsertIfNotExists
only work withBulkInsert
- The mapping should only be done once. In your case, you are probably better to use a mapping context: https://dapper-plus.net/getting-started-mapping#instance-context-mapping (you can map the same entity more than once using a mapper key as well)
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.
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.
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 aPatient
- 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 theBulkMerge
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.
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.
Thank you again @JonathanMagnan really appreciate you!
from dapper-plus.
Related Issues (20)
- Adding a list property to another table HOT 2
- Optimal batch size for SQL Server HOT 9
- A transport-level error for NVarchar(max) column when using auditing HOT 7
- Received an invalid column length from the bcp client for colid HOT 3
- Set ColumnSynchronizeDeleteKeySubsetExpression without .Entity<Whatever>()? HOT 4
- IndexOutOfRangeException on BulkMerge operations HOT 1
- ILogger not logging, but Console.WriteLine works? HOT 3
- Configure Merge for concurrency handling HOT 3
- Ids not coming back after first BulkInsert HOT 4
- Update trigger on target table causes BulkMerge to fail HOT 3
- Feature Request - suppress update if nothing changed. HOT 2
- BulkInsert doesn't generate primary key for multiple concurrent submission HOT 7
- Support for Sybase for Bulk Insert HOT 1
- Skip duplicate records on bulk insert HOT 5
- Avoid output HOT 7
- BulkInsert Postgres => An error occured while retrieving the InformationSchemaTable information. See the inner exception for details. HOT 4
- Dapper Plus can't map Id when use galera cluster HOT 3
- bulk insert very slow on mariadb version≥10.6.0 HOT 2
- Bulk Insert throws the exception 'Unknown data type' whenever inserting GUID to MySQL HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dapper-plus.