【问题标题】:No overload for method ... takes 10 arguments. But arguments/parameters match方法没有重载 ... 需要 10 个参数。但是参数/参数匹配
【发布时间】:2020-03-29 11:34:54
【问题描述】:

我有一个通过 LINQ 和 EF 调用的存储过程,它返回一个计数,并且该存储过程已经过试验和测试。

需要10个参数。

这些是存储过程采用的参数:

@StartDate DATETIME,
@EndDate DATETIME,
@Wards CodeTable READONLY,
@Clinicians CodeTable READONLY,
@Sites CodeTable READONLY,
@Specialities CodeTable READONLY,
@excludeCurrentInpatients BIT,
@DemoMode BIT,
@SortOrder Int,
@IsCurrent bit

这就是我在 LINQ 中的称呼方式:

public int Inpatient_Count(DateTime? startDate, DateTime? endDate, List<string> wards, List<string> clinicians, List<string> sites, List<string> specialities, bool excludeCurrentInpatients, bool demoMode, int sortOrder, bool IsCurrent)
{
    using (DBName context = new DBName())
    {
        int total = context.SPROC_Name(startDate, endDate, wards, clinicians, sites, specialities, excludeCurrentInpatients, demoMode, sortOrder, IsCurrent);
        return total;
    }
}

我不断收到错误:

“SPROCName”的任何重载方法都需要 10 个参数

但我传递了十个参数。任何帮助将不胜感激。

【问题讨论】:

  • 该过程在数据库中有 10 个参数并不意味着您的代码模型也正确反映了这一点。尝试刷新您的模型。如果这不起作用,请仔细检查您的代码和您正在查看的数据库是否相同。
  • 这不是LINQ,只是正常使用EF。另外,我不确定您是否可以直接传入列表。见here
  • 谢谢大家,我刷新了模型,现在它给了我另一个警告,说实体框架不支持(表类型)。
  • 你在 Core 吗?还是框架?
  • 我在框架中

标签: c# sql entity-framework linq tsql


【解决方案1】:

你可以这样做:

    public bool Import(IEnumerable<SqlDataRecord> entities, string storedProcedureName)
    {
        var paramDate = new SqlParameter("@StartDate", SqlDbType.DateTime)
        {
            Value = DateTime.Now
        }; 

        var paramTable = new SqlParameter("@Wards", SqlDbType.Structured)
        {
            TypeName = "CodeTable",
            Value = entities.ToList()
        };

        var returnValue = _dbContext.Database.ExecuteSqlCommand($"{storedProcedureName} @StartDate, @Wards", paramDate, paramTable);
        return true;

    }

修改它以满足您的需要,并提供所需的参数。

【讨论】:

    猜你喜欢
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多