From d8a45dac5bf1f545e23e7c160c3d8fe98d5d3a06 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 15 Apr 2021 02:04:55 +0100 Subject: [PATCH 1/5] set direction in default ctor and sync ctor call chains between netfx and netcore --- .../src/Microsoft/Data/SqlClient/SqlParameter.cs | 7 ++----- .../src/Microsoft/Data/SqlClient/SqlParameter.cs | 13 +++---------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs index 2bab7e4dbd..2e9b89b7e6 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -244,6 +244,7 @@ public SqlParameter() : base() { _isNull = true; _actualSize = -1; + _direction = ParameterDirection.Input; } /// @@ -725,11 +726,7 @@ public override object Value ] public override ParameterDirection Direction { - get - { - ParameterDirection direction = _direction; - return (direction != 0) ? direction : ParameterDirection.Input; - } + get => _direction; set { if (_direction != value) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs index 26174a9b67..ffb345dc21 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -227,6 +227,7 @@ public SqlParameter() : base() { _isNull = true; _actualSize = -1; + _direction = ParameterDirection.Input; } /// @@ -276,16 +277,12 @@ public SqlParameter( DataRowVersion sourceVersion, object value ) - : this() + : this(parameterName, dbType, size, sourceColumn) { - ParameterName = parameterName; - SqlDbType = dbType; - Size = size; Direction = direction; IsNullable = isNullable; PrecisionInternal = precision; ScaleInternal = scale; - SourceColumn = sourceColumn; SourceVersion = sourceVersion; Value = value; } @@ -712,11 +709,7 @@ public override object Value ] public override ParameterDirection Direction { - get - { - ParameterDirection direction = _direction; - return (direction != 0) ? direction : ParameterDirection.Input; - } + get => _direction; set { if (_direction != value) From a31408cbf13ea07a807497980db453039f99d21b Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 15 Apr 2021 02:32:23 +0100 Subject: [PATCH 2/5] convert SqlParameter xml schema fields to SqlMetaDataXmlSchemaCollection --- .../Microsoft/Data/SqlClient/SqlParameter.cs | 54 +++++++++++++------ .../Microsoft/Data/SqlClient/SqlParameter.cs | 54 +++++++++++++------ 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs index 2e9b89b7e6..2646725bfe 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -210,9 +210,7 @@ private InstanceDescriptor ConvertToInstanceDescriptor(SqlParameter p) private MetaType _metaType; private SqlCollation _collation; - private string _xmlSchemaCollectionDatabase; - private string _xmlSchemaCollectionOwningSchema; - private string _xmlSchemaCollectionName; + private SqlMetaDataXmlSchemaCollection _xmlSchemaCollection; private string _udtTypeName; private string _typeName; private Exception _udtLoadError; @@ -332,9 +330,13 @@ string xmlSchemaCollectionName SourceVersion = sourceVersion; SourceColumnNullMapping = sourceColumnNullMapping; Value = value; - XmlSchemaCollectionDatabase = xmlSchemaCollectionDatabase; - XmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema; - XmlSchemaCollectionName = xmlSchemaCollectionName; + if (!string.IsNullOrEmpty(xmlSchemaCollectionDatabase) || !string.IsNullOrEmpty(xmlSchemaCollectionOwningSchema) || !string.IsNullOrEmpty(xmlSchemaCollectionName)) + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Database = xmlSchemaCollectionDatabase; + _xmlSchemaCollection.OwningSchema = xmlSchemaCollectionOwningSchema; + _xmlSchemaCollection.Name = xmlSchemaCollectionName; + } } private SqlParameter(SqlParameter source) : this() @@ -405,24 +407,36 @@ public SqlCompareOptions CompareInfo [ResCategory("XML")] public string XmlSchemaCollectionDatabase { - get => _xmlSchemaCollectionDatabase ?? ADP.StrEmpty; - set => _xmlSchemaCollectionDatabase = value; + get => _xmlSchemaCollection?.Database ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Database = value; + } } /// [ResCategory("XML")] public string XmlSchemaCollectionOwningSchema { - get => _xmlSchemaCollectionOwningSchema ?? ADP.StrEmpty; - set => _xmlSchemaCollectionOwningSchema = value; + get => _xmlSchemaCollection?.OwningSchema ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.OwningSchema = value; + } } /// [ResCategory("XML")] public string XmlSchemaCollectionName { - get => _xmlSchemaCollectionName ?? ADP.StrEmpty; - set => _xmlSchemaCollectionName = value; + get => _xmlSchemaCollection?.Name ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Name = value; + } } /// @@ -981,9 +995,11 @@ private void CloneHelper(SqlParameter destination) destination._metaType = _metaType; destination._collation = _collation; - destination._xmlSchemaCollectionDatabase = _xmlSchemaCollectionDatabase; - destination._xmlSchemaCollectionOwningSchema = _xmlSchemaCollectionOwningSchema; - destination._xmlSchemaCollectionName = _xmlSchemaCollectionName; + if (_xmlSchemaCollection != null) + { + destination.EnsureXmlSchemaCollectionExists(); + destination._xmlSchemaCollection.CopyFrom(_xmlSchemaCollection); + } destination._udtTypeName = _udtTypeName; destination._typeName = _typeName; destination._udtLoadError = _udtLoadError; @@ -1019,6 +1035,14 @@ internal object CompareExchangeParent(object value, object comparand) return parent; } + private void EnsureXmlSchemaCollectionExists() + { + if (_xmlSchemaCollection is null) + { + _xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection(); + } + } + internal void FixStreamDataForNonPLP() { object value = GetCoercedValue(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs index ffb345dc21..41a5e85299 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -193,9 +193,7 @@ private InstanceDescriptor ConvertToInstanceDescriptor(SqlParameter p) private MetaType _metaType; private SqlCollation _collation; - private string _xmlSchemaCollectionDatabase; - private string _xmlSchemaCollectionOwningSchema; - private string _xmlSchemaCollectionName; + private SqlMetaDataXmlSchemaCollection _xmlSchemaCollection; private string _udtTypeName; private string _typeName; private Exception _udtLoadError; @@ -315,9 +313,13 @@ string xmlSchemaCollectionName SourceVersion = sourceVersion; SourceColumnNullMapping = sourceColumnNullMapping; Value = value; - _xmlSchemaCollectionDatabase = xmlSchemaCollectionDatabase; - _xmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema; - _xmlSchemaCollectionName = xmlSchemaCollectionName; + if (!string.IsNullOrEmpty(xmlSchemaCollectionDatabase) || !string.IsNullOrEmpty(xmlSchemaCollectionOwningSchema) || !string.IsNullOrEmpty(xmlSchemaCollectionName)) + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Database = xmlSchemaCollectionDatabase; + _xmlSchemaCollection.OwningSchema = xmlSchemaCollectionOwningSchema; + _xmlSchemaCollection.Name = xmlSchemaCollectionName; + } } private SqlParameter(SqlParameter source) : this() @@ -388,24 +390,36 @@ public SqlCompareOptions CompareInfo [ResCategory("XML")] public string XmlSchemaCollectionDatabase { - get => _xmlSchemaCollectionDatabase ?? ADP.StrEmpty; - set => _xmlSchemaCollectionDatabase = value; + get => _xmlSchemaCollection?.Database ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Database = value; + } } /// [ResCategory("XML")] public string XmlSchemaCollectionOwningSchema { - get => _xmlSchemaCollectionOwningSchema ?? ADP.StrEmpty; - set => _xmlSchemaCollectionOwningSchema = value; + get => _xmlSchemaCollection?.OwningSchema ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.OwningSchema = value; + } } /// [ResCategory("XML")] public string XmlSchemaCollectionName { - get => _xmlSchemaCollectionName ?? ADP.StrEmpty; - set => _xmlSchemaCollectionName = value; + get => _xmlSchemaCollection?.Name ?? string.Empty; + set + { + EnsureXmlSchemaCollectionExists(); + _xmlSchemaCollection.Name = value; + } } /// @@ -968,9 +982,11 @@ private void CloneHelper(SqlParameter destination) destination._metaType = _metaType; destination._collation = _collation; - destination._xmlSchemaCollectionDatabase = _xmlSchemaCollectionDatabase; - destination._xmlSchemaCollectionOwningSchema = _xmlSchemaCollectionOwningSchema; - destination._xmlSchemaCollectionName = _xmlSchemaCollectionName; + if (_xmlSchemaCollection != null) + { + destination.EnsureXmlSchemaCollectionExists(); + destination._xmlSchemaCollection.CopyFrom(_xmlSchemaCollection); + } destination._udtTypeName = _udtTypeName; destination._typeName = _typeName; destination._udtLoadError = _udtLoadError; @@ -1010,6 +1026,14 @@ internal object CompareExchangeParent(object value, object comparand) return parent; } + private void EnsureXmlSchemaCollectionExists() + { + if (_xmlSchemaCollection is null) + { + _xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection(); + } + } + internal void FixStreamDataForNonPLP() { object value = GetCoercedValue(); From 81e783ba556cb7b4dc519ec9654d6f30ab8b345c Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 15 Apr 2021 02:34:54 +0100 Subject: [PATCH 3/5] replace ADP.StrEmpty uses in SqlParameter with string.Empty --- .../netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs | 8 ++++---- .../netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs index 2646725bfe..723e713585 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -467,7 +467,7 @@ public override DbType DbType /// public override string ParameterName { - get => _parameterName ?? ADP.StrEmpty; + get => _parameterName ?? string.Empty; set { if ( @@ -672,7 +672,7 @@ public object SqlValue ] public string UdtTypeName { - get => _udtTypeName ?? ADP.StrEmpty; + get => _udtTypeName ?? string.Empty; set => _udtTypeName = value; } @@ -683,7 +683,7 @@ public string UdtTypeName ] public string TypeName { - get => _typeName ?? ADP.StrEmpty; + get => _typeName ?? string.Empty; set { _typeName = value; @@ -824,7 +824,7 @@ private void ResetSize() [ResCategory("Update")] public override string SourceColumn { - get => _sourceColumn ?? ADP.StrEmpty; + get => _sourceColumn ?? string.Empty; set => _sourceColumn = value; } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs index 41a5e85299..52f448e5bb 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -450,7 +450,7 @@ public override DbType DbType /// public override string ParameterName { - get => _parameterName ?? ADP.StrEmpty; + get => _parameterName ?? string.Empty; set { if ( @@ -655,7 +655,7 @@ public object SqlValue ] public string UdtTypeName { - get => _udtTypeName ?? ADP.StrEmpty; + get => _udtTypeName ?? string.Empty; set => _udtTypeName = value; } @@ -666,7 +666,7 @@ public string UdtTypeName ] public string TypeName { - get => _typeName ?? ADP.StrEmpty; + get => _typeName ?? string.Empty; set { _typeName = value; @@ -807,7 +807,7 @@ private void ResetSize() [ResCategory("Update")] public override string SourceColumn { - get => _sourceColumn ?? ADP.StrEmpty; + get => _sourceColumn ?? string.Empty; set => _sourceColumn = value; } From 1c739d4a567973047ae7bab832307cdc0886d8e1 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 15 Apr 2021 02:37:33 +0100 Subject: [PATCH 4/5] add SqlParameter XmlSchema tests --- .../tests/FunctionalTests/SqlParameterTest.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs index 203fcc5a65..344a578b4a 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs @@ -1612,6 +1612,70 @@ public void XmlSchemaTest() Assert.Equal(" a ", p1.XmlSchemaCollectionOwningSchema); } + [Fact] + public void CreateParameterWithValidXmlSchema() + { + string xmlDatabase = "database"; + string xmlSchema = "schema"; + string xmlName = "name"; + + SqlParameter parameter = new SqlParameter("@name", SqlDbType.Int, 4, ParameterDirection.Input, 0, 0, "name", DataRowVersion.Original, false, 1, xmlDatabase, xmlSchema, xmlName); + + Assert.Equal(xmlDatabase, parameter.XmlSchemaCollectionDatabase); + Assert.Equal(xmlSchema, parameter.XmlSchemaCollectionOwningSchema); + Assert.Equal(xmlName, parameter.XmlSchemaCollectionName); + } + + [Fact] + public void CreateParameterWithEmptyXmlSchema() + { + SqlParameter parameter = new SqlParameter("@name", SqlDbType.Int, 4, ParameterDirection.Input, 0, 0, "name", DataRowVersion.Original, false, 1, string.Empty, string.Empty, string.Empty); + + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionDatabase); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionOwningSchema); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + } + + [Fact] + public void CreateParameterWithNullXmlSchema() + { + SqlParameter parameter = new SqlParameter("@name", SqlDbType.Int, 4, ParameterDirection.Input, 0, 0, "name", DataRowVersion.Original, false, 1, null, null, null); + + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionDatabase); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionOwningSchema); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + } + + [Fact] + public void CreateParameterWithoutXmlSchema() + { + SqlParameter parameter = new SqlParameter(); + + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionDatabase); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionOwningSchema); + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + } + + [Fact] + public void SetParameterXmlSchema() + { + SqlParameter parameter = new SqlParameter(); + + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + + // verify that if we set it to null we still get an empty string back + parameter.XmlSchemaCollectionName = null; + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + + // verify that if we set a value we get it back + parameter.XmlSchemaCollectionName = "name"; + Assert.Equal("name", parameter.XmlSchemaCollectionName); + + // verify that if we set it explicitly to null it reverts to empty string + parameter.XmlSchemaCollectionName = null; + Assert.Equal(string.Empty, parameter.XmlSchemaCollectionName); + } + private enum ByteEnum : byte { A = 0x0a, From 8ad04b61e6e44b279f73815c44b020a748d727bc Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Mon, 3 May 2021 22:35:44 +0100 Subject: [PATCH 5/5] from review, use EnsureXmlSchemaCollection() with return value --- .../Microsoft/Data/SqlClient/SqlParameter.cs | 26 +++++-------------- .../Microsoft/Data/SqlClient/SqlParameter.cs | 26 +++++-------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs index 723e713585..e01a5560ff 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -332,7 +332,7 @@ string xmlSchemaCollectionName Value = value; if (!string.IsNullOrEmpty(xmlSchemaCollectionDatabase) || !string.IsNullOrEmpty(xmlSchemaCollectionOwningSchema) || !string.IsNullOrEmpty(xmlSchemaCollectionName)) { - EnsureXmlSchemaCollectionExists(); + EnsureXmlSchemaCollection(); _xmlSchemaCollection.Database = xmlSchemaCollectionDatabase; _xmlSchemaCollection.OwningSchema = xmlSchemaCollectionOwningSchema; _xmlSchemaCollection.Name = xmlSchemaCollectionName; @@ -408,11 +408,7 @@ public SqlCompareOptions CompareInfo public string XmlSchemaCollectionDatabase { get => _xmlSchemaCollection?.Database ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.Database = value; - } + set => EnsureXmlSchemaCollection().Database = value; } /// @@ -420,11 +416,7 @@ public string XmlSchemaCollectionDatabase public string XmlSchemaCollectionOwningSchema { get => _xmlSchemaCollection?.OwningSchema ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.OwningSchema = value; - } + set => EnsureXmlSchemaCollection().OwningSchema = value; } /// @@ -432,11 +424,7 @@ public string XmlSchemaCollectionOwningSchema public string XmlSchemaCollectionName { get => _xmlSchemaCollection?.Name ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.Name = value; - } + set => EnsureXmlSchemaCollection().Name = value; } /// @@ -997,8 +985,7 @@ private void CloneHelper(SqlParameter destination) destination._collation = _collation; if (_xmlSchemaCollection != null) { - destination.EnsureXmlSchemaCollectionExists(); - destination._xmlSchemaCollection.CopyFrom(_xmlSchemaCollection); + destination.EnsureXmlSchemaCollection().CopyFrom(_xmlSchemaCollection); } destination._udtTypeName = _udtTypeName; destination._typeName = _typeName; @@ -1035,12 +1022,13 @@ internal object CompareExchangeParent(object value, object comparand) return parent; } - private void EnsureXmlSchemaCollectionExists() + private SqlMetaDataXmlSchemaCollection EnsureXmlSchemaCollection() { if (_xmlSchemaCollection is null) { _xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection(); } + return _xmlSchemaCollection; } internal void FixStreamDataForNonPLP() diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs index 52f448e5bb..c0a2e54021 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -315,7 +315,7 @@ string xmlSchemaCollectionName Value = value; if (!string.IsNullOrEmpty(xmlSchemaCollectionDatabase) || !string.IsNullOrEmpty(xmlSchemaCollectionOwningSchema) || !string.IsNullOrEmpty(xmlSchemaCollectionName)) { - EnsureXmlSchemaCollectionExists(); + EnsureXmlSchemaCollection(); _xmlSchemaCollection.Database = xmlSchemaCollectionDatabase; _xmlSchemaCollection.OwningSchema = xmlSchemaCollectionOwningSchema; _xmlSchemaCollection.Name = xmlSchemaCollectionName; @@ -391,11 +391,7 @@ public SqlCompareOptions CompareInfo public string XmlSchemaCollectionDatabase { get => _xmlSchemaCollection?.Database ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.Database = value; - } + set => EnsureXmlSchemaCollection().Database = value; } /// @@ -403,11 +399,7 @@ public string XmlSchemaCollectionDatabase public string XmlSchemaCollectionOwningSchema { get => _xmlSchemaCollection?.OwningSchema ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.OwningSchema = value; - } + set => EnsureXmlSchemaCollection().OwningSchema = value; } /// @@ -415,11 +407,7 @@ public string XmlSchemaCollectionOwningSchema public string XmlSchemaCollectionName { get => _xmlSchemaCollection?.Name ?? string.Empty; - set - { - EnsureXmlSchemaCollectionExists(); - _xmlSchemaCollection.Name = value; - } + set => EnsureXmlSchemaCollection().Name = value; } /// @@ -984,8 +972,7 @@ private void CloneHelper(SqlParameter destination) destination._collation = _collation; if (_xmlSchemaCollection != null) { - destination.EnsureXmlSchemaCollectionExists(); - destination._xmlSchemaCollection.CopyFrom(_xmlSchemaCollection); + destination.EnsureXmlSchemaCollection().CopyFrom(_xmlSchemaCollection); } destination._udtTypeName = _udtTypeName; destination._typeName = _typeName; @@ -1026,12 +1013,13 @@ internal object CompareExchangeParent(object value, object comparand) return parent; } - private void EnsureXmlSchemaCollectionExists() + private SqlMetaDataXmlSchemaCollection EnsureXmlSchemaCollection() { if (_xmlSchemaCollection is null) { _xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection(); } + return _xmlSchemaCollection; } internal void FixStreamDataForNonPLP()