Web mình bị lỗi lệnh LINQ mà mình kiểm tra thấy rất bình thường? bạn nào biết giúp mình với. Nó báo lỗi như sau: LINQ to Entities does not recognize the method 'System.DateTime AddMonths(Int32)' method, and this method cannot be translated into a store expression. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.DateTime AddMonths(Int32)' method, and this method cannot be translated into a store expression. Code của mình: Mã: var model = dbc.Products .Where(p => p.Available && p.UnitPriceAgencyOld != null && p.UnitPriceAgencyOld > 0 && p.UnitPriceAgencyOld != p.UnitPriceAgency && p.DateUpUnitPriceAgency >= DateTime.Now.AddMonths(-1)); Mình đã thử đổi lại, adddays, addyears đều bị lỗi tương tự.
Nó có thông báo là cái AddMonths không được hỗ trợ trong câu lệnh linQ ý bạn, bạn chỉ cần tách nó ra là được ngay. Sửa lại thành: Mã: var datenow = DateTime.Now.AddMonths(-1); var model = dbc.Products .Where(p => p.Available && p.UnitPriceAgencyOld != null && p.UnitPriceAgencyOld > 0 && p.UnitPriceAgencyOld != p.UnitPriceAgency && p.DateUpUnitPriceAgency >= datenow);