コード例 #1
0
        public static void Initialize(ContactContext context)
        {
            context.Database.EnsureCreated();

            if (context.Contacts.Any())
            {
                return;
            }

            var contacts = ContactsGenerator.GenerateContacts();

            context.Contacts.AddRange(contacts);

            context.SaveChanges();
        }
コード例 #2
0
        void Initialize()
        {
            var contents = string.Empty;

            if (File.Exists(fullPath))
            {
                contents = File.ReadAllText(fullPath);
            }

            if (string.IsNullOrWhiteSpace(contents))
            {
                myContacts = ContactsGenerator.GenerateContacts();

                File.WriteAllText(fullPath, contents);
            }
            else
            {
                myContacts = JsonSerializer.Deserialize <List <Contact> >(contents);
            }

            isInitialized = true;
        }