diff --git a/build/build.fsproj b/build/build.fsproj index 3686fb1a..5b2f053e 100644 --- a/build/build.fsproj +++ b/build/build.fsproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 diff --git a/src/SqlClient.DesignTime/SqlClientProvider.fs b/src/SqlClient.DesignTime/SqlClientProvider.fs index 50044859..fdd1a8f8 100644 --- a/src/SqlClient.DesignTime/SqlClientProvider.fs +++ b/src/SqlClient.DesignTime/SqlClientProvider.fs @@ -295,11 +295,13 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this = ?defaultValue = x.TryGetValue("default_constraint"), ?description = x.TryGetValue("description") ) - if c.DefaultConstraint <> "" && c.PartOfUniqueKey + if c.DefaultConstraint <> "" && c.Nullable && c.PartOfUniqueKey then { c with PartOfUniqueKey = false } - //ADO.NET doesn't allow nullable columns as part of primary key - //remove from PK if default value provided by DB on insert. + //ADO.NET doesn't allow null values in primary key columns. + //Only remove nullable columns from PK when they have a default value, + //since nullable+default columns may be omitted in NewRow() and remain null. + //Non-nullable columns with defaults should stay in PK - callers must supply them. else c ) |> Seq.toList