locked
Call procedure in asp.net mvc5 EF6 w/o parameters RRS feed

  • Question

  • User-12940986 posted

    Hi, 

    I have this procedure that I try to call:

    CREATE PROCEDURE [dbo].[PipelineProcedure]
    AS
    SELECT p.PipelineID,max(PipelineJobStatus.CreatedTimeStamp),Client.ClientName,FCO.NameFCO,p.ProjectValueHr,p.ProjectValueMoney, p.CommentPipeline, PipelineJobStatus.CreatedTimeSTamp,p.ModifiedTimeStamp,Employee.Name,Employee.Surname, JobStatus.JobStatusName
    FROM (Pipeline p LEFT OUTER JOIN PipelineJobStatus ON p.PipelineID=PipelineJobStatus.PipelineID)
    INNER JOIN JobStatus ON (PipelineJobStatus.JobStatusID=JobStatus.JobStatusID)
    LEFT OUTER JOIN Client ON (p.ClientID = Client.ClientID)
    LEFT OUTER JOIN FCO ON (p.FCOID = FCO.FCOID) 
    LEFT OUTER JOIN Employee ON (p.CreatedBy = Employee.EmployeeD)
    Where PipelineJobStatus.CreatedTimeStamp in (select max(CreatedTimeStamp) from PipelineJobStatus group by PipelineID)
    Group By p.PipelineID,Client.ClientName,FCO.NameFCO,p.ProjectValueHr,p.ProjectValueMoney, p.CommentPipeline, PipelineJobStatus.CreatedTimeSTamp,p.ModifiedTimeStamp,Employee.Name,Employee.Surname, JobStatus.JobStatusName
    
    GO
    

    in my model, I declared variable List <PipelineProcedure_Result>:

    public class StatusPipelineMerge:IEntityBase{
    ...
    SalesManagementEntities db = new SalesManagementEntities();
            public List<PipelineProcedure_Result> Procedure()
            {
                return db.PipelineProcedure().ToList();
            }
    }

    In my controller, I've created a variable:

    StatusPipelineMerge merge = new StatusPipelineMerge();
                List<PipelineProcedure_Result> result = merge.Procedure();
                return View(result);

    In my view, I referenced a model to PipelineProcedure_Result:

    @using MVC.Controllers
    @using DataAccess
    @model IEnumerable<DataAccess.PipelineProcedure_Result>
    @*@model IEnumerable <DataAccess.PipelineJobStatu>*@
    
    @{
        ViewBag.Title = "Index";
    }
    
    @section NumberingCSS{
        @Styles.Render("~/Content/numbering-css")
    }
    
    @section NumberingJS{
        @Scripts.Render("~/bundles/numbering-js")
    }
    
    
    <h2>Index</h2>
    
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table id="example" class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Client)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CommentPipeline)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedBy)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedTimeStamp)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Employee1)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.FCO)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ModifiedTimeStamp)
                </th>
                <th>
                    Options
                </th>
            </tr>
        <tfoot>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Client)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CommentPipeline)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedBy)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedTimeStamp)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Employee1)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.FCO)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ModifiedTimeStamp)
                </th>
                <th>
                    Options
                </th>
            </tr>
        </tfoot>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.ClientName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CommentPipeline)
                    </td>
                </tr>
              }
       </tbody>
    </table>

    I get an error, when I try to view page:

    The data reader is incompatible with the specified 'SalesManagement.PipelineProcedure_Result'. A member of the type, 'Column1', does not have a corresponding column in the data reader with the same name.

    My question to you: Is that for some reason because, I didnt declare parameters in my stored procedure? What shall I do?

    Thanks in advance,

    Thursday, January 28, 2016 7:19 PM

Answers

  • User-271186128 posted

    Hi hektor,

    Welcome to asp.net forum.

    The data reader is incompatible with the specified 'SalesManagement.PipelineProcedure_Result'. A member of the type, 'Column1', does not have a corresponding column in the data reader with the same name.

    As for this issue, I suggest you check the code in the PipelineProcedure_Result class, perhaps it contains the extra column Column1.

    Besides, I suggest you could modify your code as below:

            public List<PipelineProcedure_Result> Procedure()
            {
                var query = db.PipelineProcedure().ToList();
                List<PipelineProcedure_Result> list = new List<PipelineProcedure_Result>();
                foreach(var item in query)
                {
                    PipelineProcedure_Result result = new PipelineProcedure_Result();
                    
                    result.PipelineID = item.PipelineID;
                    //other fields.
    
                    list.Add(result);
                }
                return list;
            }

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 29, 2016 2:25 AM

All replies

  • User-271186128 posted

    Hi hektor,

    Welcome to asp.net forum.

    The data reader is incompatible with the specified 'SalesManagement.PipelineProcedure_Result'. A member of the type, 'Column1', does not have a corresponding column in the data reader with the same name.

    As for this issue, I suggest you check the code in the PipelineProcedure_Result class, perhaps it contains the extra column Column1.

    Besides, I suggest you could modify your code as below:

            public List<PipelineProcedure_Result> Procedure()
            {
                var query = db.PipelineProcedure().ToList();
                List<PipelineProcedure_Result> list = new List<PipelineProcedure_Result>();
                foreach(var item in query)
                {
                    PipelineProcedure_Result result = new PipelineProcedure_Result();
                    
                    result.PipelineID = item.PipelineID;
                    //other fields.
    
                    list.Add(result);
                }
                return list;
            }

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 29, 2016 2:25 AM
  • User-12940986 posted

    Thanks Zhi!

    It's working now. I oversaw agregatefunction that I didnt give a name in SQL procedure.

    Thanks.

    Friday, January 29, 2016 10:08 AM