I have been working on this for days because I use emoji strings as unique tokens in DbBontext. the following code has been used against SqlServer 2019 express with Visual Studio 2019 as well as my older versions. My goal was to create random 5 emoji strings, store them in SqlServer using Entity Framework .NET Framework. Then be able to use DbContext to query them. There is some problem with LINQ. It is exampled here. I created a SqlServer DB with two columns, one the PK and one an indexed column. Both ad Varchar(255). I popoulate them with emoji 5 character emoji pairs that are identical. ie context.RomanEmpires.Add(new RomanEmpire() { Romulus = "♥⚡♥⌚㊙", Remus = "♥⚡♥⌚㊙" }); They all successfully insert into the DB and are visible using SSMS 2019 However the following code yields unusable results.
var listOfEntries = context.RomanEmpires.ToList();
foreach (var line in listOfEntries)
{
context.RomanEmpires.Remove(line);
}
context.SaveChanges();
context.RomanEmpires.Add(new RomanEmpire() { Romulus = "♥⚡♥⌚㊙", Remus = "♥⚡♥⌚㊙" });
context.RomanEmpires.Add(new RomanEmpire() { Romulus = "", Remus = "" });
context.RomanEmpires.Add(new RomanEmpire() { Romulus = "⚡⌚", Remus = "⚡⌚" });
context.SaveChanges();
string toMatch = "";
var matchedEntry = context.RomanEmpires.FirstOrDefault(e => e.Romulus == toMatch);
var listofMatches = context.RomanEmpires.Where(e => e.Romulus == toMatch).Count();
var listofNotMatches = context.RomanEmpires.Where(e => e.Romulus != toMatch).Count();
context.RomanEmpires.Add(new RomanEmpire() { Romulus = "", Remus = "" });
string toMatch = ""; finds a match om matched entry the "Add in the last line of code finds a duplicate insertion exception with a primary key violation. Therefore, the SqlServer evaluates a single Remus in conflict with