1

I'm trying to build a function to query a table that uses a column of type XML.

This is my code:

public int GetTotalQueue(string queueCode)
{
    int queueNumber = 0;

    QueueEntities _context = new QueueEntities();

    try
    {
            var data = (from a in _context.QueueTable
                        where a.QueueStatusId == 5
                        && a.Workgroup == "Group H"
                        && a.ExtraData.Cast<string>().Contains<string>(queueCode)
                        select a.QueueId).Count();
            queueNumber = data;
    }
    catch (Exception ex)
    {
         ExceptionHandler(ex);
         throw;
    }

    return queueNumber;
}

Extra data is the XML type column. I tried casting it to a string to do a contains but when I try to actually run this method in the wcf tester the service just fails with a non descriptive internal error. Does anyone have any suggestions on what I can do to fix this query? Am I messing up my cast? Any help would be appreciated. Thanks!

Jota.Toledo
  • 27,293
  • 11
  • 59
  • 73
Rick Kountz
  • 41
  • 2
  • 11
  • Cast Linq function doesn't work in all types conversion, refer to this for more details (https://stackoverflow.com/questions/2819473/linq-cast-extension-method-fails-but-typeobject-works). I would suggest to use Select method instead of cast: a.ExtraData.Select(x => x.ToString()).Contains(queueCode) – Abdullah Dibas Sep 24 '19 at 19:06

0 Answers0