示例#1
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            DbUtilis.CreateSqliteDb();
        }
示例#2
0
        static void Main(string[] args)
        {
            using (var db = new BloggingContext())
            {
                if (db.Database.EnsureDeleted() && db.Database.EnsureCreated())
                {
                    DbUtilis.CreateSqliteDb();
                    db.SaveChanges();
                }
            }

            using (var db = new BloggingContext())
            {
                var query = db.Blogs;

                var sql = "";
                try
                {
                    var blogs = db.Query(
                        query,
                        new EFModelInfoProvider(db),
                        new SqliteObjectFactory(),
                        out sql);

                    var json = JsonConvert.SerializeObject(blogs, new JsonSerializerSettings
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                        Formatting            = Formatting.Indented
                    });

                    Console.WriteLine("Result:");
                    Console.WriteLine(json);
                }
                finally
                {
                    Console.WriteLine("Sql:");
                    Console.WriteLine(sql);
                }
            }
        }