0

Is it possible to set charset for filtering, inserting in Entity Framework not changing database default charset

If I execute raw SQL, filtering works, but if I use objects, it fails if there are special characters.

Working

var sql = string.Format("SELECT * From Products p Where p.Name= '{0}'", productName);
var test = db.Products.FromSqlRaw(sql).FirstOrDefault();

Not working

var product = db.Products.FirstOrDefault(f => f.Name ==productName))

When defining charset in connection string it only works if reading data.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
xcold
  • 1
  • 3
  • Please provide a [mre], including relevant DDL (with explicit character sets!). It sounds like your columns are character set `NONE`, which is something you shouldn't use. As an aside, changing the database default character set would have no effect. The database default character set only specifies the character set used when creating a column without an explicit character set. – Mark Rotteveel Feb 25 '21 at 07:47
  • the old thumb rule of SQL - don't use string splicing, use SQL Parameters instead. https://www.bobby-tables.com – Arioch 'The Feb 25 '21 at 10:39
  • `only works if reading data` - your published here code does not do anything else, if the code never writes data then of course only reading would work. // Basically it seems to be about debugging your source data AND your predicate (filtering) function. Set a breakpoint inside the filtering function and check every row, how function calculates `True` or `False` and why it is doing so – Arioch 'The Feb 25 '21 at 10:45

0 Answers0