Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Mistake in AddLanguageIfNotExists method #1445


User avatar
0
omital created

Hi, I think that method "AddLanguageIfNotExists" in template with this code

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();
        }

must be

private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.Any(l => (l.TenantId == language.TenantId || (l.TenantId.HasValue==false && language.TenantId.HasValue==false)) && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);

            _context.SaveChanges();
        }

2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    This is not needed since EF should automatically do it. There was a bug in EF dynamicfilters which causes this exception and we downgraded it: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1209">https://github.com/aspnetboilerplate/as ... ssues/1209</a>

  • User Avatar
    0
    omital created

    Thank you for your response.