Ejemplo n.º 1
0
            public async Task ReturnsData2()
            {
                var dbContextOptionsBuilder = new DbContextOptionsBuilder();

                using (var connection = CreateInMemoryDatabase())
                {
                    _ = dbContextOptionsBuilder.UseSqlite(connection);

                    var modelBuilder = SqliteConventionSetBuilder.CreateModelBuilder();
                    _ = modelBuilder.Entity <TestEntity>();

                    ModelBuilderHelpers.ConvertAllDateTimeOffSetPropertiesOnModelBuilderToLong(modelBuilder);

                    var model = modelBuilder.FinalizeModel();

                    dbContextOptionsBuilder = dbContextOptionsBuilder.UseModel(model);

                    using (var dbContext = new TestWithContextOptionsDbContext(dbContextOptionsBuilder.Options))
                    {
                        _ = dbContext.Database.EnsureCreated();

                        var result = await dbContext.TestEntity
                                     .Where(GetSelector())
                                     .ToArrayAsync()
                                     .ConfigureAwait(false);
                    }
                }
            }
Ejemplo n.º 2
0
        public IModel GetModel()
        {
            var conventionSet = SqliteConventionSetBuilder.Build();
            var modelBuilder  = new ModelBuilder(conventionSet);

            modelBuilder.ApplyConfigurationsFromAssembly(_assemblyProvider.GetEntityMappingAssembly());

            return(modelBuilder.Model.FinalizeModel());
        }
Ejemplo n.º 3
0
        public static string Test()
        {
            //var bot = new Bot("");
            var profile  = new TwitterProfile("profile");
            var profileP = new TwitterProfile("profileP");
            var tweet1   = new Tweet {
                Text = @"Two years after an accident left @albertopajariyo in a wheelchair and unable to communicate, he returned to Twitter thanks to technology. Welcome back, Alberto!"
            };
            var tweet2 = new Tweet {
                Text = @"We recently found a bug that stored passwords unmasked in an internal log. We fixed the bug and have no indication of a breach or misuse by anyone. As a precaution, consider changing your password on all services where you’ve used this password."
            };
            var tweet3 = new Tweet {
                Text = @"We encourage you to update the app as we will no longer continue to support previous versions beginning on June 1. We’re doing this to focus on providing our Windows users with the latest and greatest, like night mode, which is coming soon."
            };

            var opt = new DbContextOptionsBuilder <TwitterContext>();

            opt.UseSqlite(@"Filename=C:\Project\TwitterBot\TwitterBot.Infrastructure\DbManager\TwitterBot.db");
            //opt.UseSqlServer("Server = (localdb)\\mssqllocaldb; Database = TwitterBot; Trusted_Connection = True;");
            opt.EnableSensitiveDataLogging();

            var conv = SqliteConventionSetBuilder.Build();
            //var conv = SqlServerConventionSetBuilder.Build();

            var model = new ModelBuilder(conv);

            model.Entity <TwitterProfile>();
            //model.Entity<Word>();
            model.Entity <WordOccurrence>().HasOne(w => w.Word);
            model.Entity <WordOccurrence>().HasMany(w => w.NextWordOccurrences).WithOne(n => n.Parent).OnDelete(DeleteBehavior.Restrict);
            //model.Entity<NextWordOccurrence>().HasOne(w => w.Word);
            model.Entity <NextWordOccurrence>().HasOne(w => w.Parent);
            //model.Entity<WordOccurrence>().HasMany(w => w.NextWords);
            //model.Entity<NextWordOccurrence>().HasKey(w => new { w.WordId, w.FollowedById });
            //model.Entity<WordOccurrence>().HasMany(w => w.NextWords).WithOne(n => n.Word);
            //model.Entity<NextWordOccurrence>().HasOne("WordOccurrence", "WordId").WithMany("WordOccurrence");

            opt.UseModel(model.Model);

            //using (var context = new TwitterContext(opt.Options))
            //{
            //    var repo = new TwitterProfileRepository(context);

            //    context.Database.EnsureDeleted();
            //    context.Database.EnsureCreated();

            //    repo.Add(profile);
            //    repo.Add(profileP);
            //}

            using (var context = new TwitterContext(opt.Options))
            {
                var repo = new TwitterProfileRepository(context);

                var profile2 = repo.Get(new TwitterProfile {
                    Name = "profile"
                });
                var profile22 = repo.Get(new TwitterProfile {
                    Name = "profileP"
                });

                //bot.AddProfile(profile22);

                //return bot.GenerateTweet().Text;
                return("test");
            }
        }
 protected override ConventionSet CreateConventionSet() => SqliteConventionSetBuilder.Build();
Ejemplo n.º 5
0
 public override ModelBuilder GetModelBuilder() => new ModelBuilder(SqliteConventionSetBuilder.Build());
 protected override ModelBuilder CreateConventionalModelBuilder() => new ModelBuilder(SqliteConventionSetBuilder.Build());
 protected override ConventionSet CreateConventionSet()
 {
     return(SqliteConventionSetBuilder.Build());
 }
Ejemplo n.º 8
0
 protected override ModelBuilder GetModelBuilder()
 => SqliteConventionSetBuilder.CreateModelBuilder();