Пример #1
0
 public List <Customer> SelectWithoutTransaction()
 {
     using var reader = store.BeginReadTransaction();
     return(EnsureResults(
                reader.Query <Customer>().Where("FirstName = @name").Parameter("name", "Robert").Take(100).ToList()
                ));
 }
Пример #2
0
        public override void SetUp()
        {
            base.SetUp();
            var config = new RelationalStoreConfiguration(ConnectionString);

            config.DocumentMaps.Register(new BigObjectMap(Format));

            store           = new RelationalStore(config);
            readTransaction = store.BeginReadTransaction();

            using var writer = store.BeginWriteTransaction();
            var rand         = new Random(42);
            var randomString = new Func <string>(() =>
            {
                var buffer = new byte[3];
                rand.NextBytes(buffer);
                return(Convert.ToBase64String(buffer));
            });
            var historyEntries = Enumerable.Range(1, DocumentSize / 256).Select(n => new BigObjectHistoryEntry
            {
                Id = Guid.NewGuid(), Comment = randomString(), LuckyNumbers = Enumerable.Range(0, rand.Next(130, 330)).ToArray(), Date = DateTime.Today.AddDays(n)
            });

            writer.Insert(new BigObject {
                Id = "BigObject-1", History = historyEntries.OfType <object>().ToList()
            });
            writer.Commit();
        }
Пример #3
0
        public void Load()
        {
            // If you know the document ID you want, you can load it back
            using var transaction = store.BeginReadTransaction();
            var person = transaction.Load <Person>("Persons-1");

            person.FirstName.Should().Be("Donald");
        }
Пример #4
0
        public override void SetUp()
        {
            base.SetUp();

            var config = new RelationalStoreConfiguration(ConnectionString);

            config.DocumentMaps.Register(new CustomerMap());

            store       = new RelationalStore(config);
            transaction = store.BeginReadTransaction();
        }
Пример #5
0
        public override void SetUp()
        {
            base.SetUp();
            var config = new RelationalStoreConfiguration(ConnectionString);

            config.DocumentMaps.Register(new CustomerMap());

            store       = new RelationalStore(config);
            transaction = store.BeginReadTransaction();

            allIdsRandomlySorted = transaction.Query <Customer>().ToList().Select(p => p.Id).OrderByDescending(p => Guid.NewGuid()).ToList();
        }
        public override void SetUp()
        {
            base.SetUp();
            var config = new RelationalStoreConfiguration(ConnectionString);

            config.DocumentMaps.Register(new BigObjectMap(JsonStorageFormat.TextOnly));

            store           = new RelationalStore(config);
            readTransaction = store.BeginReadTransaction();

            using var writer = store.BeginWriteTransaction();

            var history = GenerateHistory();
            var doc1    = history.Take(1).ToList();
            var doc10   = history.Take(10).ToList();
            var doc100  = history.Take(100).ToList();
            var doc500  = history.Take(500).ToList();

            var rand = new Random(42);

            for (var i = 0; i < 1000; i++)
            {
                var doc = new BigObject {
                    Name = "Document " + i
                };

                var distribution = rand.Next(1, 100);
                if (distribution < 70)
                {
                    doc.History = doc1;
                }
                else if (distribution < 85)
                {
                    doc.History = doc10;
                }
                else if (distribution < 95)
                {
                    doc.History = doc100;
                }
                else if (distribution <= 100)
                {
                    doc.History = doc500;
                }

                writer.Insert(doc, new InsertOptions {
                    CommandTimeout = TimeSpan.FromSeconds(180)
                });
                if (i % 100 == 0)
                {
                    Console.WriteLine($"Inserted: {i} history: {doc.History.Count} rand: {distribution}");
                }
            }

            foreach (var item in writer.Stream <(long?Bucket, int?Count)>(
                         "select len([JSON]) as Bucket, count(*) from BigObject group by len([JSON]) order by len([JSON])"))
            {
                Console.WriteLine($"{item.Bucket} bytes: {item.Count} documents");
            }

            writer.Commit();
        }