简体   繁体   English

模型不包含的定义,也没有扩展方法

[英]Model does not contain a definition for and no extension method

The database that I inherited has a LOT of poorly written stored procedures that I am not allowed to change because they are being used in other programs and there are too many to rewrite all of them. 我继承的数据库有很多写得不好的存储过程,我不允许更改它们,因为它们正被其他程序使用,并且有太多的东西无法重写它们。 I am trying to get rid of duplicates by using Linq GroupBy but I am getting the error that the "Model" does not contain a definintion for the field, which of course, it does. 我试图通过使用Linq GroupBy消除重复项,但是我得到一个错误,即“模型”不包含该字段的定义,当然它包含。 I'm sure this is something simple that I am missing. 我敢肯定,这是我所缺少的简单东西。 Any assistance is greatly appreciated! 非常感谢您的协助!

Here is my code: 这是我的代码:

public async Task<ActionResult> GetIncidentColumns()
        {
            int questionClusterID = 25;
            var getcolumns = await CommonClient.GetIncidentColumnsForClusterID(questionClusterID);
            var columns = getcolumns.GroupBy(c => c).Select(grp => grp.IncidentColumnID).ToArray();
            return Json(columns, JsonRequestBehavior.AllowGet);
        }

Here is the model: 这是模型:

public class IncidentColumnsModel
    {
        public int IncidentTabulationID { get; set; }
        public int IncidentColumnID { get; set; }
        public string vchColumnReference { get; set; }
        public Nullable<int> ColumnNameID { get; set; }
        public Nullable<byte> intSequence { get; set; }
        public string vchHeaderCssClass { get; set; }
        public string vchColumnHeaderText { get; set; }
        public string vchToolTip { get; set; }
        public string vchColumnCssClass { get; set; }
        public Nullable<byte> intHeaderRow { get; set; }
        public Nullable<bool> bitStartHeaderTextAboveColumn { get; set; }
        public string vchHeaderTextAboveColumn { get; set; }
        public Nullable<byte> intHeaderTextAboveColumnCount { get; set; }
        public string vchHeaderTextAboveColumnColor { get; set; }
        public Nullable<byte> intColumnPrecicion { get; set; }
        public Nullable<byte> intColumnScale { get; set; }
        public Nullable<bool> bitCalculatedColumn { get; set; }
        public Nullable<bool> bitAllowDataEntry { get; set; }
        public Nullable<bool> bitIncludeInSummaryRow { get; set; }
        public Nullable<byte> ColumnSummaryTypeID { get; set; }
        public Nullable<byte> intFormulaNumeratorASeqNum { get; set; }
        public Nullable<byte> intFormulaNumeratorBSeqNum { get; set; }
        public Nullable<byte> intFormulaNumeratorCSeqNum { get; set; }
        public Nullable<byte> intFormulaNumeratorDSeqNum { get; set; }
        public Nullable<byte> intFormulaNumeratorESeqNum { get; set; }
        public Nullable<decimal> decFormulaNumeratorMultiplier { get; set; }
        public Nullable<bool> bitThisIsARatio { get; set; }
        public Nullable<byte> intFormulaDenomeratorFSeqNum { get; set; }
        public Nullable<byte> intFormulaDenomeratorGSeqNum { get; set; }
        public Nullable<byte> intFormulaDenomeratorHSeqNum { get; set; }
        public Nullable<byte> intFormulaDenomeratorISeqNum { get; set; }
        public Nullable<byte> intFormulaDenomeratorJSeqNum { get; set; }
        public Nullable<decimal> decFormulaDenomeratorMultiplier { get; set; }
        public Nullable<bool> bitFormulaValidate { get; set; }
        public string vchValidateOnFormulaText { get; set; }
        public Nullable<byte> intValidateGTESeqNum { get; set; }
        public Nullable<decimal> decValidateGTEMultiplier { get; set; }
        public Nullable<byte> intValidateLTSeqNum { get; set; }
        public Nullable<decimal> decValidateLTMultiplier { get; set; }
        public Nullable<bool> bitRangeValidate { get; set; }
        public string vchValidateOnRangeText { get; set; }
        public Nullable<decimal> decRangeValidGTE { get; set; }
        public Nullable<decimal> decRangeValidLT { get; set; }
        public Nullable<bool> bitRequiredField { get; set; }
        public string vchAssociatedDetailColumn { get; set; }
        public string vchAssociatedSummaryColumn { get; set; }
        public Nullable<byte> intColumnPositionFromLeft { get; set; }
        public Nullable<byte> intValidateGTESeqNumB { get; set; }
        public Nullable<byte> intValidateGTESeqNumC { get; set; }
        public Nullable<byte> intValidateLTSeqNumB { get; set; }
        public Nullable<byte> intValidateLTSeqNumC { get; set; }
        public Nullable<bool> bitRolling12MonthCalculation { get; set; }
        public Nullable<bool> bitRolling4QuarterCalculation { get; set; }
        public Nullable<byte> intSummaryFormulaNumeratorASeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaNumeratorBSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaNumeratorCSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaNumeratorDSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaNumeratorESeqNum { get; set; }
        public Nullable<decimal> decSummaryFormulaNumeratorMultiplier { get; set; }
        public Nullable<bool> bitSummaryThisIsARatio { get; set; }
        public Nullable<byte> intSummaryFormulaDenomeratorFSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaDenomeratorGSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaDenomeratorHSeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaDenomeratorISeqNum { get; set; }
        public Nullable<byte> intSummaryFormulaDenomeratorJSeqNum { get; set; }
        public Nullable<decimal> decSummaryFormulaDenomeratorMultiplier { get; set; }
    }

. GroupBy () returns an object of type IEnumerable<IGrouping<TKey, TSource>> . GroupBy ()返回IEnumerable<IGrouping<TKey, TSource>>类型的对象。

Does IGrouping having a property called IncidentColumnID ? IGrouping是否具有名为IncidentColumnID的属性?

You need only one column which is ID so you should be grouping on IncidentColumnID and then project it on IncidentColumnID by writing: 您只需要一个ID列,因此您应该对IncidentColumnID进行分组,然后通过编写以下内容将其投影在IncidentColumnID

var columns = getcolumns.GroupBy(c => c.IncidentColumnID)
                        .Select(grp => grp.First())
                        .ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM