using System.Collections.Generic;
using System.Data.Entity;
using System.Linq.Dynamic.Core;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
public static void Main()
var context = new EntityContext();
var config = new ParsingConfig
CustomTypeProvider = new MyCustomTypeProvider()
var query91 = new [] { new { Campo1 = "ÁÉÍÓÚ" }, new { Campo1 = "PÓÚ" } , new { Campo1 = "PATO" } }.AsQueryable();
var result91 = query91.Select(c=> c.Campo1.Replace("Á", "A").Replace("Ó", "O"));
FiddleHelper.WriteTable(result91);
var result92 = context.X.Select(c=> c.Campo1.Replace("Á", "A").Replace("Ó", "O"));
FiddleHelper.WriteTable(result92);
var result93 = context.X.Select("Campo1.Replace(\"Á\", \"A\").Replace(\"Ó\", \"O\")");
FiddleHelper.WriteTable(result93);
var query2 = new [] { new { Value = (string) null }, new { Value = "100" } }.AsQueryable();
var result2 = query2.Select("Utils.ParseAsInt(Value)");
FiddleHelper.WriteTable(result2);
var result51 = context.X.Where(c=> DbFunctions.Like(c.Value, "%00%") ).Select(c=> c.Value);
FiddleHelper.WriteTable(result51);
var result52 = context.X.Where(config, " DbFunctions.Like(Value, \"_2_\") ").Select("Value");
FiddleHelper.WriteTable(result52);
var result53 = context.X.Where(config, " DbFunctions.Like(Value, \"%00%\") ").Select(c=> c.Value);
FiddleHelper.WriteTable(result53);
public static void GenerateData()
new X { Value = null, Campo1="ÁÉÍÓÚ" },
new X { Value = "100", Campo1="PÉPe" },
new X { Value = "222", Campo1="LÁÚ" },
new X { Value = "300", Campo1="LÉÓ" },
new X { Value = "320", Campo1="SÁÓÚ" }
using (var context = new EntityContext())
context.X.AddRange(list);
context.BulkSaveChanges();
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<X> X { get; set; }
public int Id { get; set; }
public string Value { get; set; }
public string Campo1 { get; set; }
public static class Utils
public static string ParseAsString(string value)
public static int ParseAsInt(string value)
public static string RemoveDiacritics(string text)
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder(capacity: normalizedString.Length);
for (int i = 0; i < normalizedString.Length; i++)
char c = normalizedString[i];
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
.Normalize(NormalizationForm.FormC);
class MyCustomTypeProvider : DefaultDynamicLinqCustomTypeProvider
public override HashSet<Type> GetCustomTypes()
var result = base.GetCustomTypes();
result.Add(typeof(System.Data.Entity.DbFunctions));