Solved

Problem with LINQ to entities on a XML field in database

Posted on 2009-05-07
1
561 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:Nargzul
1 Comment
 
LVL 11

Accepted Solution

by:
Salim Fayad earned 500 total points
ID: 24339725
try to replace line 2 by the following:

IQueryable<Fournisseurs> fourns = gse.Fournisseurs.Where(f => f.Informations.ToString().Contains(prefixText));

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question