tags:

views:

171

answers:

1

Using Linq to call a stored procedure that passes a single string, The stored procedure returns a data set row that contains a string and an int.

Code:

 PESQLDataContext pe = new PESQLDataContext(strConnStr);
        pe.ObjectTrackingEnabled = false;

 gvUnitsPassed.DataSource = pe.PassedInspection(Line);
 gvUnitsPassed.DataBind();

pe.dispose();

When the code runs an exception gets called below: The exception is thrown at the IExecuteResult result = statement: Enclosed is my result class in the designer.cs file.

[Function(Name = "dbo.PassedInspection")]
    public ISingleResult<PassedInspectionResult> PassedInspection([Parameter(Name = "Model", DbType = "VarChar(4)")] string model)
    {
        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), model);
        return ((ISingleResult<PassedInspectionResult>)(result.ReturnValue));
    }

    public partial class PassedInspectionResult
    {

        private string _Date;

        private int _Passed;

        public PassedInspectionResult()
        {
        }

        [Column(Storage = "_Date", DbType = "string NULL")]
        public string Date
        {
            get
            {
                return this._Date;
            }
            set
            {
                if ((this._Date != value))
                {
                    this._Date = value;
                }
            }
        }

        [Column(Storage = "_Passed", DbType = "Int NULL")]
        public int Passed
        {
            get
            {
                return this._Passed;
            }
            set
            {
                if ((this._Passed != value))
                {
                    this._Passed = value;
                }
            }
        }
    }
}

I have other stored procedures with similar arguments that run just fine.

Thanks

+1  A: 

I'm pretty sure it's this line causing the problem:

[Column(Storage = "_Date", DbType = "string NULL")]

Specifically the "string" bit. It should be the datatype the field is defined as in the stored proc. eg varchar(...), ntext etc.

Foole
Yes, Thanks that was the issue. When I first added the stored proc to the designer I had the argument as char(4). Then I received the above error. So I changed the argument to varchar(4). I must have transposed the string argument. In testing I removed the stored procedure, replaced the argument as char(4) and re added the proc.It now maps as varchar(4) even though it is a char(4) in the stored procedure. Thanks for the help.
Joe Pitz