runtime icon indicating copy to clipboard operation
runtime copied to clipboard

System.Data.Common.DbParameter does not implement IDbDataParameter in an overridable way

Open jonwagner opened this issue 9 years ago • 6 comments

System.Data.Common.DbParameter does not implement IDbDataParameter in an overridable way.

Effects: accessing a SqlParameter through the IDbDataParameter interface returns invalid Precision/Scale/Size properties.

Example:

     var sql = new SqlParameter();
     sql.Precision = 5;
     var idb = (IDbDataParameter)sql;
     Assert.AreEqual(sql.Precision, idb.Precision); // fails because IDbDataParameter.Precision is hard-coded to 0

In https://github.com/dotnet/corefx/blob/master/src/System.Data.Common/src/System/Data/Common/DbParameter.cs:

        byte IDbDataParameter.Precision
        {
            get { return 0; }
            set { }
        }

        byte IDbDataParameter.Scale
        {
            get { return 0; }
            set { }
        }

        public virtual byte Precision
        {
            get { return ((IDbDataParameter)this).Precision; }
            set { ((IDbDataParameter)this).Precision = value; }
        }

        public virtual byte Scale
        {
            get { return ((IDbDataParameter)this).Scale; }
            set { ((IDbDataParameter)this).Scale = value; }
        }

In https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameter.cs:

        public override Byte Scale
        {
            get
            {
                return ScaleInternal;
            }
            set
            {
                ScaleInternal = value;
            }
        }

jonwagner avatar May 25 '17 16:05 jonwagner

Seems to have been introduced in the .NET core 2.0 branch as part of the IDbDataParameter implementation.

jonwagner avatar May 25 '17 16:05 jonwagner

@saurabh500 @corivera this looks like 2.0 blocker ... thoughts?

karelz avatar May 25 '17 19:05 karelz

~~This is a dupe of https://github.com/dotnet/corefx/issues/19708 PR with fix is https://github.com/dotnet/corefx/pull/19961~~ The correct PR is dotnet/corefx#19734 and the issue is dotnet/runtime#21675

saurabh500 avatar May 25 '17 19:05 saurabh500

To me, it looks like the error is in the DbParameter code.

@saurabh500 I don't see how this is related to the issue/pr you referenced. 19708 is an issue with TVPs and only fixes SqlParameter.

jonwagner avatar May 25 '17 19:05 jonwagner

@jonwagner My mistake, I linked the wrong PR and issue. The correct PR is https://github.com/dotnet/corefx/pull/19734 and the issue is https://github.com/dotnet/corefx/issues/19712

saurabh500 avatar May 25 '17 19:05 saurabh500

Yes, that's the correct duplicate. 👍

jonwagner avatar May 25 '17 19:05 jonwagner