Meilleur auteur de réponses
problème avec linq

Question
-
pour être bref voilà le code
public void update(Func<Produit, bool > condition, Action<Produit> chagement) { Produit[] cls = (mdb.Produits.Where(condition)).ToArray<Produit>(); foreach (Produit c in cls) { chagement(c); } mdb.SubmitChanges(); }
try { gg.update(p => p.FullName=="nom" , p => p.FullName = "nom_i" ); } catch (Exception ex) { Console.WriteLine(ex.Message+"\n" +ex.Source); }
j'obtiens cette exception:
There was an error parsing the query. [ Token line number = 3,Token line offset = 1,Token in error = WHERE ]
quelqu'un peut m'aider?
Réponses
-
Salut,
Je viens de tester ton code avec les classes suivantes, ça m'a l'air correcte. Je n'ai pas d'exception :
class Produit { private String _FullName; public String FullName { get { return _FullName; } set { _FullName = value; } } public Produit(String nom) { this._FullName = nom; } } class mdb { public static List<Produit> Produits = new List<Produit>() { new Produit("skate"), new Produit("roller") }; internal static void SubmitChanges() { throw new NotImplementedException(); } } class Program { private static void update(Func<Produit, bool> condition, Action<Produit> changement) { Produit[] cls = (mdb.Produits.Where(condition)).ToArray<Produit>(); foreach (Produit c in cls) { changement(c); } mdb.SubmitChanges(); } public static void Main() { try { update(p => p.FullName == "nom", p => p.FullName = "nom_i"); } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.Source); } }
Remarque tu peux passer par le langages de requetes aussi :
IEnumerable<string> query1 = from p in mdb.Produits
where conditions
select p;- Marqué comme réponse Gilles TOURREAUModerator mardi 1 décembre 2009 22:25
Toutes les réponses
-
-
Salut,
Je viens de tester ton code avec les classes suivantes, ça m'a l'air correcte. Je n'ai pas d'exception :
class Produit { private String _FullName; public String FullName { get { return _FullName; } set { _FullName = value; } } public Produit(String nom) { this._FullName = nom; } } class mdb { public static List<Produit> Produits = new List<Produit>() { new Produit("skate"), new Produit("roller") }; internal static void SubmitChanges() { throw new NotImplementedException(); } } class Program { private static void update(Func<Produit, bool> condition, Action<Produit> changement) { Produit[] cls = (mdb.Produits.Where(condition)).ToArray<Produit>(); foreach (Produit c in cls) { changement(c); } mdb.SubmitChanges(); } public static void Main() { try { update(p => p.FullName == "nom", p => p.FullName = "nom_i"); } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.Source); } }
Remarque tu peux passer par le langages de requetes aussi :
IEnumerable<string> query1 = from p in mdb.Produits
where conditions
select p;- Marqué comme réponse Gilles TOURREAUModerator mardi 1 décembre 2009 22:25