[SQL SERVER] Dealing with nulls values and timestamp columns during insert
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the SQL Server path using localCtx.Dbo.WriteStorages.Create(x.ColumnValues), then review how null values and timestamp columns are handled during inserts. Done means the sync can insert these records without replacing nulls with DBNull.Value or filtering timestamp columns manually.
Written by the indexing model from the issue text.
Description
Description
As an exercise I've ported a small console application that sync tables in SQL SERVER DB from C# EF to F# SQLProvider.
In C# I was able to do the following:
foreach (Type t in types)
{
List<object> remoteEntities = await remoteContext.Set(t).ToListAsync();
var localEntities = await localContext.Set(t).ToListAsync();
localContext.Set(t).RemoveRange(localEntities);
localContext.Set(t).AddRange(remoteEntities);
}
await localContext.SaveChangesAsync();
In F# It became something like this:
...deleting old entities...
remoteCtx.Dbo.WriteStorages |> Seq.map (fun x-> localCtx.Dbo.WriteStorages.Create(x.ColumnValues)) |> Seq.toList
Actual behavior
This approach was failing due to 2 errors:
-
null had to be replaced with
System.DBNull.Valueand it was producing errors like:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll: 'The parameterized query '(@param0 uniqueidentifier,@param1 datetime,@param2 nvarchar(14),' expects the parameter '@param3', which was not supplied.' -
should filter Timestamp column from ColumnValues because of errors like:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll: 'Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.'
For EF It's working out-of-box, so maybe SQLProvider could also take care of these cases?
Known workarounds
Do the replacements mentioned above.
Related information
- SQL SERVER
- Windows
- .NET Runtime
- Dominant language
- F#
- Stars
- 627
- Forks
- 147
- Avg merge
- 2h 2m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fsprojects/SQLProvider
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 55/100
fsprojects/SQLProvider#872 · 2 comments ·
-
Repo Assist? Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 10/100
fsprojects/SQLProvider#870 · 1 comment ·
-
postgresql
Difficulty 4/5 3-5 days Newbie friendliness 58/100
fsprojects/SQLProvider#869 · 2 comments ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
fsprojects/SQLProvider#868 · 2 comments ·
-
sql server
Difficulty 4/5 3-5 days Newbie friendliness 45/100
fsprojects/SQLProvider#851 · 1 comment ·
All issues in fsprojects/SQLProvider
Similar issues
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
[BUG] A column whose default is the empty string is drawn in the ER diagram as having no default Openbug database-provider good first issue hacktoberfest
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
libredb/libredb-studio#1030 · 6 comments ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug redshift
Difficulty 2/5 1-3 hours Newbie friendliness 88/100