/// <summary> /// loads sample data into the database. /// </summary> public static void LoadSampleData(DemoDataContext dataCtx, int numItems = 1000) { if (dataCtx.Contacts.Count() != numItems) { dataCtx.RemoveRange(dataCtx.Contacts.ToList()); dataCtx.SaveChanges(); dataCtx.RemoveRange(dataCtx.NotesWithoutFullText.ToList()); dataCtx.SaveChanges(); dataCtx.RemoveRange(dataCtx.NotesWithFulltext.ToList()); dataCtx.SaveChanges(); string[] emailDomains = new string[] { "gmail.com", "outlook.com", "yahoo.com", "balsamicsoftware.org" }; foreach (NameInfo nameInfo in RandomStuff.RandomNames(numItems, emailDomains, null, 5)) { Contact addMe = new Contact(nameInfo); dataCtx.Contacts.Add(addMe); } dataCtx.SaveChanges(); for (int idx = 0; idx < numItems; idx++) { string noteText = RandomStuff.RandomSentance(100, 2048); string noteTopic = RandomStuff.RandomSentance(50, 512); NoteWithFulltext noteWith = new NoteWithFulltext { Topic = noteTopic, Note = noteText }; NoteWithoutFulltext noteWithOut = new NoteWithoutFulltext { Topic = noteTopic, Note = noteText }; dataCtx.NotesWithFulltext.Add(noteWith); dataCtx.NotesWithoutFullText.Add(noteWithOut); dataCtx.SaveChanges(); } } }
static void Main(string[] args) { var db = new DemoDataContext(); Console.Write("Nombre del nuevo log: "); var nuevoLog = new Log() { Text = Console.ReadLine() }; if (!string.IsNullOrEmpty(nuevoLog.Text)) { db.Logs.Add(nuevoLog); Console.WriteLine($"Guardando log {nuevoLog.Text}..."); db.SaveChanges(); } foreach (var log in db.Logs) { Console.WriteLine($"{log.Id} - {log.Text}"); } Console.ReadLine(); }
public UserEntity Create(UserEntity userEntity) { _context.User.Add(userEntity); _context.SaveChanges(); return(userEntity); }