Esempio n. 1
0
        public void RetrieveSealed()
        {
            using (Transaction tr = new Transaction())
                using (new EntityCache(EntityCacheType.ForceNewSealed))
                {
                    var albums = Database.Query <AlbumEntity>().ToList();

                    Assert2.AssertAll(GraphExplorer.FromRoots(albums), a => a.Modified == ModifiedState.Sealed);

                    Assert2.Throws <InvalidOperationException>("sealed", () => albums.First().Name = "New name");


                    var notes = Database.Query <NoteWithDateEntity>().ToList();
                    Assert2.AssertAll(GraphExplorer.FromRoots(notes), a => a.Modified == ModifiedState.Sealed);

                    //tr.Commit();
                }
        }
Esempio n. 2
0
        public void SaveManyMList()
        {
            using (Transaction tr = new Transaction())
                using (OperationLogic.AllowSave <AlbumEntity>())
                    using (OperationLogic.AllowSave <ArtistEntity>())
                    {
                        var prev = Database.MListQuery((AlbumEntity a) => a.Songs).Count();

                        var authors =
                            Database.Query <BandEntity>().Take(6).ToList().Concat <IAuthorEntity>(
                                Database.Query <ArtistEntity>().Take(8).ToList()).ToList();

                        List <AlbumEntity> albums = 0.To(16).Select(i => new AlbumEntity()
                        {
                            Name   = "System Greatest hits {0}".FormatWith(i),
                            Author = i < authors.Count ? authors[i] : new ArtistEntity {
                                Name = ".Net Framework"
                            },
                            Year  = 2001,
                            Songs = { new SongEntity {
                                          Name = "Compilation {0}".FormatWith(i)
                                      } },
                            State = AlbumState.Saved
                        }).ToList();

                        albums.SaveList();

                        Assert2.AssertAll(GraphExplorer.FromRoots(albums), a => !a.IsGraphModified);

                        Assert.AreEqual(prev + 16, Database.MListQuery((AlbumEntity a) => a.Songs).Count());

                        albums.ForEach(a => a.Name += "Updated");

                        albums.SaveList();

                        albums.ForEach(a => a.Songs.ForEach(s => s.Name = "Updated"));

                        albums.SaveList();

                        //tr.Commit();
                    }
        }
Esempio n. 3
0
        public void SaveMList()
        {
            using (Transaction tr = new Transaction())
                using (OperationLogic.AllowSave <AlbumEntity>())
                    using (OperationLogic.AllowSave <ArtistEntity>())
                    {
                        var prev = Database.MListQuery((AlbumEntity a) => a.Songs).Count();

                        Type[] types = typeof(int).Assembly.GetTypes().Where(a => a.Name.Length > 3 && a.Name.StartsWith("A")).ToArray();

                        AlbumEntity album = new AlbumEntity()
                        {
                            Name   = "System Greatest hits",
                            Author = new ArtistEntity {
                                Name = ".Net Framework"
                            },
                            Year  = 2001,
                            Songs = types.Select(t => new SongEntity()
                            {
                                Name = t.Name
                            }).ToMList(),
                            State = AlbumState.Saved
                        }.Save();

                        Assert2.AssertAll(GraphExplorer.FromRoot(album), a => !a.IsGraphModified);

                        Assert.AreEqual(prev + types.Length, Database.MListQuery((AlbumEntity a) => a.Songs).Count());

                        album.Name += "Updated";

                        album.Save();

                        album.Songs.ForEach(a => a.Name = "Updated");

                        album.Save();

                        //tr.Commit();
                    }
        }