0

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

“数据读取器与指定模型“backupmodel.company”不兼容。companyid 类型的成员,在数据读取器中没有同名的对应列。

如何纠正这个..请提出解决方案..

存储过程:

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");
        }
4

1 回答 1

0

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

于 2013-07-11T17:50:04.980 回答