数据读取器与模型不兼容。该类型的成员,数据读取器中没有相应的列具有相同的名称

时间:2013-02-22 07:19:17

标签: asp.net-mvc-3 entity-framework

我正在使用实体框架,我必须使用存储过程更新表,但我收到错误

“数据阅读器与指定的型号”backupmodel.company“不兼容。属于该类型的companyid的成员,数据阅读器中没有相应的列具有相同的名称。” < / p>

如何纠正这个......请建议解决..

存储过程:

ALTER PROCEDURE [dbo].[sp_UpdateCompany]
(
     @CompanyId int
    ,@CompanyName varchar(50)
    ,@CompanyUrl varchar(50)
    ,@CompanyType varchar(50)
    ,@Country varchar(50)
    ,@State varchar(50)
    ,@ZipCode varchar(10)
    ,@Industry varchar(50)
    ,@RevenueSize int
    ,@Vertical int
    ,@Employee int
)
as
BEGIN
    set @CompanyUrl=REPLACE(@CompanyUrl,' ','') 
    UPDATE Companies 
    SET
    CompanyName=@CompanyName,
    CompanyUrl=@CompanyUrl,
    CompanyType=@CompanyType,
    Country=@Country,
    State=@State,
    ZipCode=@ZipCode,
    Industry=@Industry,
    RevenueSize=@RevenueSize,
    Vertical=@Vertical,
    EmpSize=@Employee
    where
    CompanyId=@CompanyId    
END

显示错误:

public ObjectResult<Company> sp_UpdateCompany(Nullable<global::System.Int32> companyId, global::System.String companyName, global::System.String companyUrl, global::System.String companyType, global::System.String country, global::System.String state, global::System.String zipCode, global::System.String industry, Nullable<global::System.Int32> revenueSize, Nullable<global::System.Int32> vertical, Nullable<global::System.Int32> employee)
    {
        ObjectParameter companyIdParameter;
        if (companyId.HasValue)
        {
            companyIdParameter = new ObjectParameter("CompanyId", companyId);
        }
        else
        {
            companyIdParameter = new ObjectParameter("CompanyId", typeof(global::System.Int32));
        }

        ObjectParameter companyNameParameter;
        if (companyName != null)
        {
            companyNameParameter = new ObjectParameter("CompanyName", companyName);
        }
        else
        {
            companyNameParameter = new ObjectParameter("CompanyName", typeof(global::System.String));
        }

        ObjectParameter companyUrlParameter;
        if (companyUrl != null)
        {
            companyUrlParameter = new ObjectParameter("CompanyUrl", companyUrl);
        }
        else
        {
            companyUrlParameter = new ObjectParameter("CompanyUrl", typeof(global::System.String));
        }

        ObjectParameter companyTypeParameter;
        if (companyType != null)
        {
            companyTypeParameter = new ObjectParameter("CompanyType", companyType);
        }
        else
        {
            companyTypeParameter = new ObjectParameter("CompanyType", typeof(global::System.String));
        }

        ObjectParameter countryParameter;
        if (country != null)
        {
            countryParameter = new ObjectParameter("Country", country);
        }
        else
        {
            countryParameter = new ObjectParameter("Country", typeof(global::System.String));
        }

        ObjectParameter stateParameter;
        if (state != null)
        {
            stateParameter = new ObjectParameter("State", state);
        }
        else
        {
            stateParameter = new ObjectParameter("State", typeof(global::System.String));
        }

        ObjectParameter zipCodeParameter;
        if (zipCode != null)
        {
            zipCodeParameter = new ObjectParameter("ZipCode", zipCode);
        }
        else
        {
            zipCodeParameter = new ObjectParameter("ZipCode", typeof(global::System.String));
        }

        ObjectParameter industryParameter;
        if (industry != null)
        {
            industryParameter = new ObjectParameter("Industry", industry);
        }
        else
        {
            industryParameter = new ObjectParameter("Industry", typeof(global::System.String));
        }

        ObjectParameter revenueSizeParameter;
        if (revenueSize.HasValue)
        {
            revenueSizeParameter = new ObjectParameter("RevenueSize", revenueSize);
        }
        else
        {
            revenueSizeParameter = new ObjectParameter("RevenueSize", typeof(global::System.Int32));
        }

        ObjectParameter verticalParameter;
        if (vertical.HasValue)
        {
            verticalParameter = new ObjectParameter("Vertical", vertical);
        }
        else
        {
            verticalParameter = new ObjectParameter("Vertical", typeof(global::System.Int32));
        }

        ObjectParameter employeeParameter;
        if (employee.HasValue)
        {
            employeeParameter = new ObjectParameter("Employee", employee);
        }
        else
        {
            employeeParameter = new ObjectParameter("Employee", typeof(global::System.Int32));
        }

        return base.ExecuteFunction<Company>("sp_UpdateCompany", companyIdParameter, companyNameParameter, companyUrlParameter, companyTypeParameter, countryParameter, stateParameter, zipCodeParameter, industryParameter, revenueSizeParameter, verticalParameter, employeeParameter);
    }

我正在调用存储过程,如:

BDE_backupEntities obj = new BDE_backupEntities();
 public ActionResult Save(string Name, string Url, string RecordOwner)
        {
            var x = obj.Companies.ToList();
            x = (from n in obj.Companies where n.CompanyUrl.Contains(Url) select n).ToList();
            int? Id=x[0].CompanyId;
            obj.sp_UpdateCompany(Id, Name, Url, "solutions", "USA", "us", "s1234", "IT", 0, 0, 0);
            return View("CompanyDetails");
        }

1 个答案:

答案 0 :(得分:0)

如果您正在使用EF并将存储过程与输出参数一起使用,则需要在函数导入中将返回类型标记为NONE。