none
SqlCommandBuilder.DeriveParameters in Dot Net Core RRS feed

  • Question

  • I was porting <g class="gr_ gr_35 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="35" id="35">a old</g> class lib to dot net core. unable to use "SqlCommandBuilder.DeriveParameters(this.Command);".
    Is there any <g class="gr_ gr_103 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="103" id="103">work around</g> for this in Dot Net <g class="gr_ gr_136 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" data-gr-id="136" id="136">Core ?</g>

     public CommandBuilder AssignParameters(object p)
      {
        SqlCommandBuilder.DeriveParameters(this.Command);   
        if (p == null) return this;
        var objType = p.GetType();    
        var props = TypeExtensions.GetProperties(objType).Cast<PropertyInfo>().ToList();        
        
        foreach (SqlParameter parameter in this.Command.Parameters)
        {
            if (parameter.ParameterName == "@RETURN_VALUE" || parameter.Direction == ParameterDirection.Output)
                continue;
            var paramName = parameter.ParameterName.Remove(0, 1);
            var prop = props.FirstOrDefault(obj => paramName.Equals(obj.Name, StringComparison.OrdinalIgnoreCase));
            if (prop != null)
            {
                var propType = prop.PropertyType;
                var propValue = prop.GetValue(p);
                if (parameter.DbType == DbType.Int32)
                {
                    var intValue = propValue.ToInt();
                    if (intValue == 0)
                    {
                        parameter.Value = DBNull.Value;
                    }
                    else
                    {
                        parameter.Value = intValue;
                    }
                }
                else if (propType == typeof(DateTime))
                {
                    var propVal = propValue.ToDateTime();
                    parameter.Value = propVal == DateTime.MinValue ? null : propValue;
                }                    
                else
                {
                    parameter.Value = (propValue == null || String.IsNullOrEmpty(propValue.ToString())) ? DBNull.Value : propValue;
                }
            }
            else
            {
                parameter.Value = DBNull.Value;
            }
        }

    Friday, October 13, 2017 1:18 PM

All replies

  • Hello Pradeep714,

    For .NET Core issue please choose to post on either https://github.com/dotnet/corefx or http://forums.dotnetfoundation.org/

    Your specific question has already been asked here:

    https://github.com/dotnet/corefx/issues/5501

    And I see the following "This was added in #20883 ,It will ship in 2.1.0. "

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Barry Wang Wednesday, October 18, 2017 2:19 AM
    Monday, October 16, 2017 7:41 AM