Improve compiler support in Linq partial updates
See original GitHub issueThe Linq update
builder currently accepts an anonymous record for partially updating a table.
I think it is worth considering deprecating the anonymous record support (on the Linq builder only) in favor of a setColumn
(or similarly named) operator that allows you to set individual columns.
Why? Better compiler support for partial updates with less chance of run-time exceptions!
setColumn
can be constrained to'T
which will allow the F# compiler to provide type check errors at compile-time, whereas the anonymous record approach allows potential run-time errors.
For example:
update {
for p in personTable do
set {| FirstName = "UPDATED"; LastName = "UPDATED" |}
where (p.Position = 1)
}
|> conn.UpdateAsync
would become:
update {
for p in personTable do
setColumn p.FirstName "UPDATED" // constrained to only allow properties on `p`
setColumn p.LastName "UPDATED"
where (p.Position = 1)
}
|> conn.UpdateAsync
- A less important reason (but still a nice side effect) is that removing support for anonymous records it will greatly simplify the Linq update builder implementation by removing the extra
'U
generic parameter.
Issue Analytics
- State:
- Created 2 years ago
- Comments:25 (25 by maintainers)
Top Results From Across the Web
c# - Using a partial class property inside LINQ statement
So I modified LinqKit to pull out the get{} value when it encounters a property. The way it operates on the expression is...
Read more >Adding Business Logic By Using Partial Methods - ADO.NET
In this article The code that LINQ to SQL generates defines signatures as one part of a partial method. If you want to...
Read more >LINQ to SQL (Part 4 - Updating our Database)
You can accomplish this by adding/removing data objects from the DataContext's table collections, and by then calling the SubmitChanges() method ...
Read more >Learn all about Partial Class in C# | Simplilearn
Understand what is Partial Class in C#, Advantages of Partial Class, Points that you should be careful about partial classes with example.
Read more >LINQKit is a free set of extensions for LINQ to SQL and ...
LINQKit is a free set of extensions for LINQ to SQL and Entity Framework power users. - GitHub - scottksmith95/LINQKit: LINQKit is a...
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
I think I just imagined a way to implement multi column joins in the Linq API that might work… 🤞
The multi-column join went really well! 🎉
I had to temporarily butcher the test project by removing all the broken stuff, but I saw that you are working on the tests next, so I think I will just wait for you to complete the test rework, and then I’ll get a fresh pull of the fixed branch to apply the multi-join feature. That should keep things simple.
BTW, one workaround I implemented that you might consider to get the tests up and running quickly was to add a
Legacy.fs
file to the Tests project with the old where filter functions (since they were used all over the place to unit test the Linq queries):