3

I am trying to call GetScanningLogOnSettings(), which queries the ScanningDepartments table to get the departments, then creates an instance of ApplicationLogOnModel, assigns the queried results to a variable within the ApplicationLogOnModel, and returns the result.

private ApplicationLogOnModel GetScanningLogOnSettings()
   {
       var mesEntity = new MESEntities();
       var departments = from dept in mesEntity.ScanningDepartments
                         select dept.Department.ToList();

       ApplicationLogOnModel depts = new ApplicationLogOnModel()
       {
           Department = departments
       };

       return depts;
   }

It gives me:

"Cannot implicitly convert type 'System.Linq.IQueryable<System.Collections.Generic.List<char>> to 'System.Collections.Generic.List<Models.Department>'

Tried converting to lists and am having a little trouble.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
Mark Saluta
  • 577
  • 1
  • 5
  • 12

1 Answers1

7

You are missing some parentheses:

var departments = (from dept in mesEntity.ScanningDepartments
                   select dept.Department).ToList();

Your code calls ToList() on dept.Department and not on the whole query.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • It is now saying "Cannot implicitly convert type 'System.Collections.Generic.List to 'System.Collections.Generic.List. – Mark Saluta Feb 19 '13 at 16:01
  • @MarkSaluta: That's another problem and not the scope of this question. Most likely, `dept.Department` returns a string and `ApplicationLogOnModel.Department` is not a list of strings but of `Models.Department` instances. – Daniel Hilgarth Feb 19 '13 at 16:04