0

我试图通过剖析它来了解这个存储库是如何工作的。我真的很迷茫,所以希望社区能帮助我一点。请记住,我是 MVC 的新手,所以不要让我分崩离析。我得到的错误是因为我有无效的论点。我认为这是来自我的第三个论点,但我不太确定如何解决它。

ResponentRepository.GetRespondents() 是下面的问题通知。

在我的控制器中,我有:

        List<int> projectIdsToInclude = new List<int>();
        projectIdsToInclude.Add(4);

        List<int> statusesToInclude = new List<int>();
        statusesToInclude.Add(1);

        List<string> fieldsToInclude = new List<string>();
        fieldsToInclude.Add("firstName");



        IEnumerable<int> pID = projectIdsToInclude;
        IEnumerable<string> fields = fieldsToInclude;

        var respondents = RespondentRepository.GetRespondents(UserSession, pID, statusesToInclude, fields);

在存储库中,它具有:

public List<Respondent> GetRespondents(UserSessionData sessionData, IEnumerable<int> projectIdsToInclude, IEnumerable<RespondentStatus> statusesToInclude, IEnumerable<string> fieldsToInclude)
        {
            var request = new RespondentRequest
            {
                Options = new RequestOptions
                {
                    Include = fieldsToInclude,
                    //OrderBy = new List<OrderBy> { new OrderBy { Direction = OrderByDirection.Descending, Field = Create.Name<Respondent>(r => r.LastActionDate) } },
                    Filter = new LogicExpression
                    {
                        ExpressionA = new InExpression<int>
                        {
                            Field = Create.Name<Respondent>(r => r.ProjectId),
                            Values = projectIdsToInclude.ToList()
                        },
                        ExpressionB = new InExpression<RespondentStatus>
                        {
                            Field = Create.Name<Respondent>(r => r.RecruitingStatus),
                            Values = statusesToInclude.ToList()
                        },
                        Operator = SqlOperator.And
                    },

                }
            };

            return Get(request, sessionData).Data;
        }

我认为我的无效论点来自 IEnumerable 的论点。因此,当我关注 RespondentStatus 时,我看到了这一点:

public enum RespondentStatus : int
    {
        [Description("Not Contacted")]
        NotContacted = 0,
        [Description("Pre-Screened")]
        PreScreened = 1,
        [Description("On Hold")]
        Hold = 2,
        [Description("Initial Refusal")]
        InitialRefusal = 3,
        [Description("Qualified Refusal")]
        QualifiedRefusal = 4,
        [Description("Remove From Panel")]
        RemoveFromPanel = 5,
        Terminated = 6,
        Complete = 7,
        //Probably should never reuse '8' as a status since retiring "Approved" status
        Approved = 8,

        // Phone contact statuses
        [Description("No Answer")]
        NoAnswer = 30,
        Busy = 31,
        [Description("Left Message")]
        LeftMessage = 32,
        [Description("Call Back Later")]
        CallBackLater = 33,
        [Description("Non-working Number")]
        NonWorkingNumber = 34,
    }

如何修复控制器中的代码以从该存储库中提取响应者?我只想返回一些受访者。我想如果我能做到这一点,我可以从那里进一步剖析。有人可以解释我应该怎么做才能完成这项工作或我缺少什么吗?

4

1 回答 1

1

statusesToInclude应该是IEnumerable<RespondentStatus> 你期望IEnumerable<RespondentStatus>你的方法,但是用List<int>.

更改您的方法签名或调用代码,以使两个 statusesToInclude变量匹配并具有相同的类型。

例如:

List<RespondentStatus> statusesToInclude = new List<RespondentStatus>();
        statusesToInclude.Add((RespondentStatus)1);
于 2013-10-19T00:08:46.397 回答