示例#1
0
        private void CreateSeed()
        {
            List <MS_Country> InitialCountry = new List <MS_Country>();
            List <String>     listCountry    = new List <string>()
            {
                "INA,Indonesia"
            };

            foreach (var item in listCountry)
            {
                var countrySeparate = item.Split(',');

                var countryPush = new MS_Country()
                {
                    countryCode = countrySeparate[0]
                };

                InitialCountry.Add(countryPush);
            }

            foreach (var country in InitialCountry)
            {
                AddIfNotExists(country);
            }
        }
示例#2
0
        private void AddIfNotExists(MS_Country country)
        {
            if (_context.MS_Country.Any(l => l.countryCode == country.countryCode))
            {
                return;
            }

            _context.MS_Country.Add(country);

            _context.SaveChanges();
        }