Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if XML coloumn in EF contains specific value
    text
    copied!<p>I have a question about EF and XML coloumn in the EF Model.</p> <p>I have a search page in my project with many fields. I intersect my values with code:</p> <pre><code>IQueryable&lt;ServicesRegistration&gt; query = null; using (SelfServiceEntities context = new SelfServiceEntities()) { query = context.ServicesRegistrations.Include("BanStatusType").Where(c =&gt; c.AppID == "MyApp"); if (filter.RequestStatus != null) { if (query == null) { query = context.ServicesRegistrations .Include("BanStatusType") .Where(c =&gt; c.BanStatusType.StatusID == filter.RequestStatus); } else { query = query.Where(c =&gt; c.BanStatusType.StatusID == filter.RequestStatus); } } } </code></pre> <p>This work well for all simple types like string, int etc.</p> <p>But when I try to do such operation on XML coloumn I get Exception:</p> <blockquote> <p>InnerException = {"Disallowed implicit conversion from data type xml to data type nvarchar, table 'dbo.ServicesRegistrations', column 'MetadataXml'. Use the CONVERT function to run this query."}</p> </blockquote> <p>My code is:</p> <pre><code>if (!string.IsNullOrEmpty(filter.SerialNumber)) { if (query == null) { query = context.ServicesRegistrations .Include("BanStatusType").Where(c =&gt; c.MetadataXml.Contains(filter.SerialNumber)); } else { query = query.Where(c =&gt; c.MetadataXml.Contains(filter.SerialNumber)); } } </code></pre> <p>I using Ef 3.5 and I know that there is some problem in implementation of XML data in it.</p> <p>Is somebody solve such problem? Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload