【问题标题】:Problem on using containers within models C#在模型 C# 中使用容器的问题
【发布时间】:2018-10-08 07:33:02
【问题描述】:

我尝试使用模型在存储过程执行中获取我的容器,但它说 SP.GR0007R 上的 SP 是模型的变量,它是一个变量但用作类型,但如果我使用 @改为 987654323@,没有发现错误但也没有结果。

这是我的代码:

using (var db = new SqlConnection(connStr))
{
    var param = new DynamicParameters();
    switch (filter.RPTCode)
    {
        case "GR0007R":
            param.Add("@Name", !string.IsNullOrEmpty(filter.NAME) ? filter.NAME : string.Empty);
            var sp7r = await db.QueryAsync<SP.GR0007R>(filter.RPTQuery, param, commandType: CommandType.StoredProcedure);
            break;
    }
    res = true;
}

这是我声明SP的地方

 public async Task<bool> GetReportData(Models.ReportManager.EswisReportModel SP, GetListParameterReportList filter)

这是我的模型

 public class EswisReportModel
{
    public Cont.ReportManager.GR0001R GR0001R { get; set; }
    public Cont.ReportManager.GR0002R GR0002R { get; set; }
    public Cont.ReportManager.GR0007R GR0007R { get; set; }
    public Cont.ReportManager.GR0008R GR0008R { get; set; }
    public Cont.ReportManager.GR0009R GR0009R { get; set; }
}

所以我必须转换它还是有其他方式来调用它? 谢谢

【问题讨论】:

  • 能否请您出示您尝试传递给GetReportData 方法的filter.RPTCodefilter.NAMEfilter.RPTQuery
  • 'public class GetListParameterReportList : PagedInputDto { public string RPTCode { get;放; } 公共字符串 RPTQuery { 获取;放; } 公共字符串名称 { 获取;放; } }'
  • 我的意思是你怎么调用GetReportData这个方法以及filter参数传入了什么值
  • 它是一个 API 逻辑,我在控制器上调用它,我在 RPTCode 上使用的值是“GR0007R”,你能告诉我如何使用像 thingy 这样的文本框吗?例如:过滤一个,大声笑

标签: c# api logic


【解决方案1】:

您似乎正在尝试输入实例和属性名称,并希望通用处理能够非常聪明地知道您的意思是该属性的支持类型。它没有。根据 C# 规范,您需要使用类型名称,而不是对它的引用,也不是通过变量名称对它的某种推断使用。

这就是为什么你应该使用实际的类型名称Cont.ReportManager.GR0007R

var sp7r = await db.QueryAsync<Cont.ReportManager.GR0007R>(...);

【讨论】:

  • 感谢帕特里克的回答,但就像我说的,我试过了,没有发现错误,但也没有结果
  • 它没有返回任何结果可能有很多原因。现在代码无法编译,所以它证明我的回答解决了这个问题并解释了它发生的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
  • 1970-01-01
  • 2012-05-11
相关资源
最近更新 更多