Argument data type xml is invalid for argument 1 of len function

1

I'm mapping a property to the xml-type database using Migrations .

public string Xml { get; set; }

this.Property(t => t.Xml).HasColumnName("Xml").HasColumnType("xml");

However, querying the class using Linq returns the error.

 _context.PreListaPostagemLog.Where(p => p.IdPlp == null && !string.IsNullOrEmpty(p.Xml)).ToList();
  

Argument data type xml is invalid for argument 1 of len function.

    
asked by anonymous 23.02.2016 / 14:59

1 answer

1

In SQL Server, len() does not work with XML type . You will need to use datalength() in place.

In the Entity Framework, datalength() is used like this:

_context.PreListaPostagemLog
        .Where(p => p.IdPlp == null && SqlFunctions.DataLength(p.Xml) > 0)
        .ToList();

See more about SqlFunctions here .

    
23.02.2016 / 16:44