简体   繁体   中英

Take() Throws Not Implemented Exception Entity Framework 6 with MySQL

I am getting a NotImplementedException with the message "The method or operation is not implemented." when running the following LINQ query using Entity Framework 6.0 with MySQL.

entities.Member.
    Where(m => m.MemberSite.Any(s => s.SiteID == siteID)).
    OrderByDescending(m => m.DateCreated).Take(50).ToList();

The following (minus the Take(50)) however works fine.

entities.Member.
    Where(m => m.MemberSite.Any(s => s.SiteID == siteID)).
    OrderByDescending(m => m.DateCreated).ToList();

Anybody else seen this issue and found a way around it?

I came at the solution from another angle which produces the same result. I have had issues with the Any() and All() LINQ methods in Entity Framework for MySQL before so should have know these were the issues.

Instead doing the following produces the right result.

entities.MemberSite.
    Where(s => s.SiteID == siteID).Select(s => s.Member).
    OrderBy(m => m.DateCreated).Take(50).ToList();

Is there a reason why you're not using the LINQ syntax? I think it is easier to read. This is an alternative to your solution:

from s in entities.MemberSite
where s.SiteID == siteID
orderby s.DateCreated
select s.Member).Take(50).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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