Ef Core Charset Problem
Posted: Mon 24 Jul 2017 07:38
Hello i am using ef core with .net framework 4.6.1
I am trying to use devart mysql provider.
Everything works fine when i did the configuration in my dbcontext. But there is a problem with the charset i suppose. When i run my seed methods. There is an if condition for the default languages that i am adding to my languages table. But even the values are the same. It is always adding the values to my database.
to be more specific i will share my code and connection string.
and this is the seed class that add the languages to db.
this line never returns. always adding the languages again and again to my db.
i have tried unicode=true in my connection string and i have tried the charset utf8mb4 but no luck with it.
my default collation is "utf8-default collation" in mysql db.
Any help will be appreciated.
Thanks in Advance.
CAN
I am trying to use devart mysql provider.
Everything works fine when i did the configuration in my dbcontext. But there is a problem with the charset i suppose. When i run my seed methods. There is an if condition for the default languages that i am adding to my languages table. But even the values are the same. It is always adding the values to my database.
to be more specific i will share my code and connection string.
Code: Select all
"ConnectionStrings": {
"Default": "server=***;database=BookAndAdDb;port=3306;uid=****;password=****;CharSet=utf8;"
}
Code: Select all
using System.Collections.Generic;
using System.Linq;
using Abp.Localization;
using ByteBrick.BookAndAd.EntityFrameworkCore;
namespace ByteBrick.BookAndAd.Migrations.Seed.Host
{
public class DefaultLanguagesCreator
{
public static List<ApplicationLanguage> InitialLanguages => GetInitialLanguages();
private readonly BookAndAdDbContext _context;
private static List<ApplicationLanguage> GetInitialLanguages()
{
return new List<ApplicationLanguage>
{
new ApplicationLanguage(null, "en", "English", "famfamfam-flags gb"),
new ApplicationLanguage(null, "ar", "العربية", "famfamfam-flags sa"),
new ApplicationLanguage(null, "de", "German", "famfamfam-flags de"),
new ApplicationLanguage(null, "it", "Italiano", "famfamfam-flags it"),
new ApplicationLanguage(null, "fr", "Français", "famfamfam-flags fr"),
new ApplicationLanguage(null, "pt-BR", "Portuguese", "famfamfam-flags br"),
new ApplicationLanguage(null, "tr", "Türkçe", "famfamfam-flags tr"),
new ApplicationLanguage(null, "ru", "Русский", "famfamfam-flags ru"),
new ApplicationLanguage(null, "zh-CN", "简体中文", "famfamfam-flags cn"),
new ApplicationLanguage(null, "es-MX", "Español México", "famfamfam-flags mx")
};
}
public DefaultLanguagesCreator(BookAndAdDbContext context)
{
_context = context;
}
public void Create()
{
CreateLanguages();
}
private void CreateLanguages()
{
foreach (var language in InitialLanguages)
{
AddLanguageIfNotExists(language);
}
}
private void AddLanguageIfNotExists(ApplicationLanguage language)
{
if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
{
return;
}
_context.Languages.Add(language);
_context.SaveChanges();
}
}
}
Code: Select all
if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
{
return;
}
my default collation is "utf8-default collation" in mysql db.
Any help will be appreciated.
Thanks in Advance.
CAN