Can expression in WhenMatched use both existing record and an "insert" dataset?
See original GitHub issueHi again Artiom,
I want to add just a little bit sophisticated logic in updating existing record. My expression in WhenMatched compares existing value with a new one and makes a decision:
dataContext.CompanyUsers
.Upsert(new CompanyUser(companyDto.Id, userDto.Id, userDto.Position))
.On(u => new {u.UserId, u.CompanyId})
.WhenMatched(inDb =>
new CompanyUser
{
Positions = inDb.Positions.Contains(userDto.Position) ? inDb.Positions : userDto.Position
})
.Run();
But this fails with UnsupportedExpressionException.
The following variation of the same fails too:
dataContext.CompanyUsers
.Upsert(new CompanyUser(companyDto.Id, userDto.Id, userDto.Position))
.On(u => new {u.UserId, u.CompanyId})
.WhenMatched((inDb, newOne) =>
new CompanyUser
{
Positions = inDb.Positions.Contains(newOne.Positions) ? inDb.Positions : newOne.Positions
})
.Run();
Out of curiosity I played a bit with it. But even some simple operations like
Positions = inDb.Positions + ','+ userDto.Position
fail.
Is there any work-around for this?
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Upsert into a Delta Lake table using merge
You can upsert data from a source table, view, or DataFrame into a target Delta table by using the MERGE SQL operation.
Read more >Merging Data Into an Existing Data Source With ON TABLE ...
The ON TABLE MERGE clause in a TABLE or TABLEF command enables you to insert, update, and delete records in an existing single-segment...
Read more >SQL Server MERGE Statement overview and examples
This article will review on SQL Server MERGE statement, different clauses and examples of MERGE statement in SQL Server.
Read more >Upsert into a Delta Lake table using merge
You can upsert data from a source table, view, or DataFrame into a target Delta table by using the MERGE SQL operation.
Read more >SQL MERGE INTO - How to delete then insert matched ...
I am using a MERGE INTO statement to compare these two. When it finds a match between the two tables, it updates the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Artiom,
Thanks a lot for your efforts! I will do my best to try this ASAP. Though can’t really promise since I’m quite loaded currently with other stuff. But it’s itching to try! 😄
I’ll be closing this issue since there’s been no updates in some time. If you have any other issues, please let me know