0

In my SQL SERVER I have a field Poids (type: Varchar) and when I tried to convert it to Decimal I had this error: "LINQ to Entities ne reconnaît pas la méthode 'System.Decimal Parse(System.String)'" . This my code:

  var list = db.Réception.Where(y => y.Supprimée == false).
                Select(x => new
                {
                    Id_rec = x.Id_rec,
                    N° = x.N°,
                    Date_rec = x.Date_rec.ToString(),
                    heure_rec = x.heure_rec.ToString(),
                    Qualité = x.Qualité.Qualité1,    
                    Poids = x.Wg.AsEnumerable().Where(y => y.Id_rec == x.Id_rec).Select(w => decimal.Parse(w.Poids)).Sum(),
                    Nbwg =x.Wg.Where(y => y.Id_rec == x.Id_rec).Count()    
        });

Please if someone can help me I'm blocked and I tried some solutions in web but without results.

lot
  • 39
  • 7
  • You need to materialize the query - `var list = db.Réception.Where(y => y.Supprimée == false).ToList().Select(....` –  Apr 04 '18 at 10:25
  • Also https://stackoverflow.com/search?q=%5Bentity-framework%5D+or+%5Bentity-framework-6%5D+LINQ+to+Entities+does+not+recognize – Ivan Stoev Apr 04 '18 at 10:27
  • @StephenMuecke, I tried that but I got an error : System.NullReferenceException La référence d'objet n'est pas définie à une instance d'un objet. – lot Apr 04 '18 at 10:30
  • This is an English only site. And it did solve your error (you just have another one as well) –  Apr 04 '18 at 10:35
  • please translate it to English, it will be easy to get more help or easy to communicate with you. – delta12 Apr 04 '18 at 11:47
  • Sorry,the error is: "System.NullReferenceException:Object reference not set to an instance of an object" Thanks in advance . – lot Apr 04 '18 at 13:21
  • Linq ne sait pas traduire en SQL la méthode Parse, d'où l'erreur. Peux-tu poster ton code qui te donne l'erreur actuelle ? - Linq is unable to translate Parse C# method into SQL. Can you post code giving you "NullReferenceException" ? – Florian Apr 04 '18 at 13:29

0 Answers0