public void IndexingEntries() { var db = new NewsObjectContext(); var indexingDb = new CachedDatabaseContainer(); var formatter = new BinaryFormatter(); var controller = new NouvelleController(); var counter = 0; foreach (var id in db.Entries.Select(en => en.Id)) { counter++; if (counter % 5 == 0) Debug.WriteLine(">> Indexed: " + counter); var chk = indexingDb.EntryViews.SingleOrDefault(e => e.Id == id); if (chk != null) continue; chk = new EntryView { Id = id }; var stream = new MemoryStream(); formatter.Serialize(stream, controller.GetEntryViewModel(id)); chk.Data = stream.ToArray(); indexingDb.EntryViews.AddObject(chk); stream.Close(); indexingDb.SaveChanges(); } }