[RESOLVED]values don't perpetuate in same method

Please see code below. It shows a controller file I’m working on (created by someone else and I get to work on it after the fact; oh joy) in which
sourceList, when I step through the code and mouse over, indicates that it includes subsets of SourceFileID and SourceFileDetailID (values from a db table). The person from whom I inherited the code also says those values should show from sourceList,
but the red squiggly says that it doesn’t. Any clue as to where I should go from here?

//        public ActionResult Generate([Bind(Include = "ID,Name,isFastTrack,ctResultYearID,ctResultFileTypeID,ctLEATypeID")] ResultFile resultFile, HttpPostedFileWrapper uploadedFile, FormCollection formCollection)
public ActionResult Generate([Bind(Include = "ID,Name,isFastTrack,ctTargetYearID,ctResultFileTypeID,ctLEATypeID")] ResultFile resultFile, FormCollection formCollection)
    int WPUGenYear; 
    int ResultFileTypeID = GetSourceTypeIDByName(GetSourceTemplateType(resultFile.ctLEATypeID, resultFile.isFastTrack)); 

    if (ModelState.IsValid)
        // target/result years-list from which WPUGenYear selection is available
        SelectList TargetYearList = new SelectList(db.ctTargetYears.Where(y => y.isActive), "ID", "Year");
        ViewBag.TargetYearList = TargetYearList;

        // create drop-down list for result file types 
        SelectList ResultFileTypeList = new SelectList(db.ctResultFileTypes.Where(t => t.isActive), "ID", "Name");
        ViewBag.ResultFileTypeList = ResultFileTypeList;

        // Test for sender of submit 
        if (formCollection["Generate"] == "Search")
            // method to determine ctResultFileTypeID 

            ///////////   S E A R C H 
            var ResultFileSearch = db.ResultFiles.ToList()   
                .Where(s => s.isFastTrack == resultFile.isFastTrack
                && s.ctLEATypeID == resultFile.ctLEATypeID
                && s.ctTargetYearID == s.ctTargetYearID
                && s.ctSourceFileTypeID == ResultFileTypeID  // 
                && s.ctTargetYearID == resultFile.ctTargetYearID);
            ViewBag.ResultFileSearch = ResultFileSearch; 
        } // end "Search"
        if (formCollection["Generate"] == "Generate WPUs")
            //           private String GetSourceTemplateType( int ctLEATypeID, bool IsFastTrack, string ctTargetYearYear)  { 
            //////////////////  G E N E R A T E (create WPUs) 
                string templateType;
                DateTime creationDT = new DateTime();
                creationDT = System.DateTime.Now;
                int ctResultErrorTypeID = db.ctResultErrorTypes.Where(a => a.isActive).Min(m => m.ID);  // default error checking to OK 
                bool isValidated = true; 

                // populate the source year offset list and ranges list if needed 
                if (this.sourceYearOffset == null || this.sourceYearOffset.Count() < sourceYearOffsetCount) this.BuildSourceYearOffsetList();  // build the mapping and year offset for templates to source types  
                if (this.ranges == null || this.ranges.Count() < rangesListCount) this.BuildSourceTypeRangeList();  // build the mapping and year offset for templates to source types  

                // assign the template type name 
                templateType = this.GetSourceTemplateType((int)resultFile.ctLEATypeID, resultFile.isFastTrack); 
                // build the list of data sources for template type
                List<SourceYearOffset> sourceList = new List<SourceYearOffset>();
                sourceList = getTypesForTemplate(templateType);

                // populate the Source IDs from uploaded files -- if they're all there and validated 
                if (isValidated) if (!this.isSourceListValid(ref sourceList, resultFile.ctTargetYearID))
						// Incomplete Sources error
						isValidated = false;
						ctResultErrorTypeID = 2;

				isValidated = false;
				// remove 'false' to remove bypass 
				if (isValidated) if (!(this.isLEAListValid(sourceList))) 
						// Recipient Mismatch error 
						isValidated = false;
						ctResultErrorTypeID = 3;

				isValidated = true; 
				if (isValidated)   // copy source data ranges to target template

					// write binary file to spreadsheet file
					var sourceFile = db.SourceFiles.Where(sfid => sfid.ID == sourceList.SourceFileID);
					var sourceFileDetail = db.SourceFileDetails.Where(sfdid => sfdid.ID == sourceList.SourceFileDetailID); 

...etc. ...


he person from whom I inherited the code also says those values should show from sourceList, but the red squiggly says that it doesn’t.

Where is the red squiggly? Does the code compile? 
And what is precisely the problem?

The problem is that I need to get the values of SourceFileID and SourceFileDetailID; the red squiggly appears underneath these two items. It does not compile. Even though mousing over sourceList earlier shows these two as available for use with sourceList,
they in fact aren’t available when I’m ready to use them. This is confusing to me because they’re all used in the same method and should be available.


It does not compile.

What is the error?

That the two data items don’t exist.

Can you check your table and EF code whether the table contains these two properties or not?

Hi muybn,

Base on your code, the type of soureList is the collection of SoureceYearOffset (List<SourceYearOffset>), so it doesn’t have the properties of
SourceFileID and SourceFileDetailID).

If you want to get the entities that exist in the soureList, please refer to this code below:

var sourceFile = db.SourceFiles.Where(sfid => sourceList.Any(s=>s.SourceFileID==sfid.ID));
					var sourceFileDetail = db.SourceFileDetails.Where(sfdid =>sourceList.Any(s=>s.SourceFileDetailID==sfdid.ID));

Best Regards


Thank you, Starain!

Leave a Reply