LINQ to Entities error on ToList with a one-to-many attribute

Whenever I try to run the following code

        employees = from e in this.entities.employees select e;
        var ett = (from e in employees where 
                      (e.salaries.ToList().Where(i => i.to_date.Year == 9999).First().salary1 > TT) 
                  select e);

        var etf = (from e in employees
                  where
                      (e.salaries.ToList().Where(i => i.to_date.Year == 9999).First().salary1 < TT &&
                      e.salaries.ToList().Where(i => i.to_date.Year == 9999).First().salary1 > TF)
                  select e);

        foreach (employee e in ett)
        {
            this.members.memberships.AddObject(new membership
            {
                FirstName = e.first_name,
                LastName = e.last_name,
                MembershipClass = "regular",
                VerificationCode = "abc1234"
            });
        }

        foreach (employee e in etf)
        {
            this.members.memberships.AddObject(new membership
            {
                FirstName = e.first_name,
                LastName = e.last_name,
                MembershipClass = "regular",
                VerificationCode = "abc1234"
            });
        }

i get the following error:

LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[app.salary] ToList[salary](System.Collections.Generic.IEnumerable`1[app.salary])' method, and this method cannot be translated into a store expression.

The Employee class does maintain a one-to-many relationship to salary. As far as I can read, the errors refer to a .ToList() method call, but removing them has not solved the problem.

EDIT: added more code, hopefully that helps.

Answers


I think this part: e.salaries.ToList() is the problem. You shouldn't have to do .ToList() to do linq query, try without the .ToList()

var ett = (from e in employees where 
                      (e.salaries.Where(i => i.to_date.Year == 9999).First().salary1 > TT) 
                  select e);

    var etf = (from e in employees
              where
                  (e.salaries.Where(i => i.to_date.Year == 9999).First().salary1 < TT &&
                  e.salaries.Where(i => i.to_date.Year == 9999).First().salary1 > TF)
              select e);

Need Your Help

How do I send a file as an email attachment using Linux command line?

linux bash email command-line shell

I've created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them together as a compressed .tar file. The nex...

pg_dump: connection to database “testdb” failed: FATAL: password authentication failed for user “katie”

postgresql pg-dump

I logged into PostgreSQL: psql -U postgres Created 'testdb': CREATE DATABASE testdb; Logged out: \q, Logged into 'testdb': psql -d testdb -U postgres Created some tables and sequences in 'testdb' ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.