Link to home
Start Free TrialLog in
Avatar of Nargzul
Nargzul

asked on

Problem with LINQ to entities on a XML field in database

I've a problem:

I try to access to a database with the code below, but I've an error:

System.Data.EntityCommandExecutionException: Une erreur s'est produite lors de l'exécution de la définition de la commande. Pour plus de détails, consultez l'exception interne. ---> System.Data.SqlClient.SqlException: Disallowed implicit conversion from data type xml to data type nvarchar, table 'dbo.Fournisseurs', column 'Informations'. Use the CONVERT function to run this query.

I think it's the database that say this error, but what can I do? Because I'm using Linq to Entity, It's not me who write this query.
using (geststockEntities gse = new geststockEntities("name=geststockEntitiesTechnicien"))
            {
                IQueryable<Fournisseurs> fourns = gse.Fournisseurs.Where(f => f.Informations.Contains(prefixText));
                res = new String[fourns.Count()];
 
                int i = 0;
                foreach (Fournisseurs f in fourns)
                {
                    XElement fournisseur = XElement.Parse(f.Informations.ToString());
                    res[i++] = fournisseur.Element("nom") + " (ID #" + f.ID_fournisseur + ")";
                }
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Salim Fayad
Salim Fayad
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial