Solved

Problem with LINQ to entities on a XML field in database

Posted on 2009-05-07
1
565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

734 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