You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Primary Keys and Identity Columns](#primary-keys-and-identity-columns)
46
+
-[Primary Key Special Cases](#primary-key-special-cases)
47
47
-[Known Issues](#known-issues)
48
48
-[Telemetry](#telemetry)
49
49
-[Trademarks](#trademarks)
@@ -756,20 +756,26 @@ public static IActionResult Run(
756
756
}
757
757
```
758
758
759
-
#### Primary Keys and Identity Columns
759
+
#### Primary Key Special Cases
760
760
761
761
Normally Output Bindings require two things :
762
762
763
763
1. The table being upserted to contains a Primary Key constraint (composed of one or more columns)
764
764
2. Each of those columns must be present in the POCO object used in the attribute
765
765
766
-
If either of these are falsethen an error will be thrown.
766
+
Normally ifeither of these are falsethen an error will be thrown. Below are the situations in which this is not the case:
767
767
768
-
This changes if one of the primary key columns is an identity column though. In that case there are two options based on how the functiondefines the output object:
768
+
##### Identity Columns
769
+
In the case where one of the primary key columns is an identity column, there are two options based on how the functiondefines the output object:
769
770
770
771
1. If the identity column isn't included in the output object then a straight insert is always performed with the other column values. See [AddProductWithIdentityColumn](./samples/samples-csharp/OutputBindingSamples/AddProductWithIdentityColumn.cs) for an example.
771
772
2. If the identity column is included (even if it's an optional nullable value) then a merge is performed similar to what happens when no identity column is present. This merge will either insert a new row or update an existing row based on the existence of a row that matches the primary keys (including the identity column). See [AddProductWithIdentityColumnIncluded](./samples/samples-csharp/OutputBindingSamples/AddProductWithIdentityColumnIncluded.cs) for an example.
772
773
774
+
##### Columns with Default Values
775
+
In the case where one of the primary key columns has a default value, there are also two options based on how the functiondefines the output object:
776
+
1. If the column with a default value is not included in the output object, then a straight insert is always performed with the other values. See [AddProductWithDefaultPK](./samples/samples-csharp/OutputBindingSamples/AddProductWithDefaultPK.cs) for an example.
777
+
2. If the column with a default value is included then a merge is performed similar to what happens when no default column is present. If there is a nullable column with a default value, then the provided column value in the output object will be upserted even if it is null.
778
+
773
779
## Known Issues
774
780
775
781
- Output bindings against tables with columns of data types `NTEXT`, `TEXT`, or `IMAGE` are not supported and data upserts will fail. These types [will be removed](https://docs.microsoft.com/sql/t-sql/data-types/ntext-text-and-image-transact-sql) in a future version of SQL Server and are not compatible with the `OPENJSON`functionused by this Azure Functions binding.
stringmessage=$"All primary keys for SQL table {table} need to be found in '{typeof(T)}.' Missing primary keys: [{string.Join(",",missingPrimaryKeysFromItem)}]";
// If any identity columns aren't included in the object then we have to generate a basic insert since the merge statement expects all primary key
656
+
// If any identity columns or columns with default values aren't included in the object then we have to generate a basic insert since the merge statement expects all primary key
648
657
// columns to exist. (the merge statement can handle nullable columns though if those exist)
0 commit comments