當前位置: 首頁>>代碼示例>>C#>>正文


C# OrmLiteConnectionFactory.Open方法代碼示例

本文整理匯總了C#中ServiceStack.OrmLite.OrmLiteConnectionFactory.Open方法的典型用法代碼示例。如果您正苦於以下問題:C# OrmLiteConnectionFactory.Open方法的具體用法?C# OrmLiteConnectionFactory.Open怎麽用?C# OrmLiteConnectionFactory.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ServiceStack.OrmLite.OrmLiteConnectionFactory的用法示例。


在下文中一共展示了OrmLiteConnectionFactory.Open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.AppSettings["dbConnStr"], MySqlDialect.Provider);
     var action = Request["Action"];
     var id = Request["Id"];
     List<allen_news> result = null;
     if (action == "PullDown")
     {
         var db = dbFactory.Open();
         result = db.SelectFmt<allen_news>("select * from allen_news where news_id > {0} order by news_id desc limit 0,30",id);
         db.Dispose();
     }
     else if(action == "PullUp")
     {
         var db = dbFactory.Open();
         result = db.SelectFmt<allen_news>("select * from allen_news where news_id < {0} order by news_id desc limit 0,30", id);
         db.Dispose();
     }
     else if(action == "CheckVersion")
     {
         Response.Write("1.0.2");
         Response.End();
         return;
     }
     else
     {
         var db = dbFactory.Open();
         result = db.Select<allen_news>("select * from allen_news order by news_id desc limit 0,30");
         db.Dispose();
     }
     Response.Write(JsonConvert.SerializeObject(result));
     Response.End();
 }
開發者ID:Feng2012,項目名稱:DeveloperNews,代碼行數:33,代碼來源:Default.aspx.cs

示例2: Create_Sqlite_Database

        public void Create_Sqlite_Database()
        {
            var dbPath = "~/App_Data/db.sqlite".MapAbsolutePath();
            var dbFactory = new OrmLiteConnectionFactory(
                dbPath, SqliteDialect.Provider);

            if (File.Exists(dbPath)) 
                File.Delete(dbPath);

            NorthwindData.LoadData();

            using (var db = dbFactory.Open())
            {
                db.CreateTables(overwrite:false, tableTypes:NorthwindFactory.ModelTypes.ToArray());

                db.SaveAll(NorthwindData.Categories);
                db.SaveAll(NorthwindData.Customers);
                db.SaveAll(NorthwindData.CustomerCustomerDemos);
                db.SaveAll(NorthwindData.Employees);
                db.SaveAll(NorthwindData.EmployeeTerritories);
                db.SaveAll(NorthwindData.OrderDetails);
                db.SaveAll(NorthwindData.Orders);
                db.SaveAll(NorthwindData.Products);
                db.SaveAll(NorthwindData.Products);
                db.SaveAll(NorthwindData.Regions);
                db.SaveAll(NorthwindData.Shippers);
                db.SaveAll(NorthwindData.Suppliers);
                db.SaveAll(NorthwindData.Territories);
            }
        }
開發者ID:ServiceStackV3,項目名稱:ServiceStack.Benchmarks,代碼行數:30,代碼來源:PopulateDataTests.cs

示例3: GetUsers_Test

		public void GetUsers_Test()
		{
            using (var appHost = new BasicAppHost(typeof(GetUsersService).Assembly).Init())
		    {
                var request = new GetUsers
                {
                    UserIds = new ArrayOfLong(1, 2),
                    UserNames = new ArrayOfString("User3", "User4")
                };

                var factory = new OrmLiteConnectionFactory(
                    InMemoryDb, SqliteDialect.Provider);

                using (var db = factory.Open())
                {
                    db.DropAndCreateTable<User>();
                    db.Insert(new User { Id = 1, UserName = "User1" });
                    db.Insert(new User { Id = 2, UserName = "User2" });
                    db.Insert(new User { Id = 3, UserName = "User3" });
                    db.Insert(new User { Id = 4, UserName = "User4" });

                    var handler = appHost.Resolve<GetUsersService>();

                    var response = handler.Any(request);

                    Assert.That(response.Users.Count, Is.EqualTo(4));
                }
            }
		}
開發者ID:Qasemt,項目名稱:ServiceStack.Examples,代碼行數:29,代碼來源:GetUsersTests.cs

示例4: SaveExtensionInfo

        public void SaveExtensionInfo([FromBody] string xmlString)
        {
            IDbConnectionFactory dbFactory =
              new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider);

            using (IDbConnection db = dbFactory.Open())
            {
                var doc = XDocument.Parse(xmlString);
                var dataNode = doc.Root.Elements("data").Elements("ext_install_stats_request").Elements("client_info");
                UserInfo items = (from r in dataNode
                                  select new UserInfo()
                                              {
                                                  AppId = r.Element("appid").Value.ToString(),
                                                  BrowserName = r.Element("bname").Value.ToString(),
                                                  BrowserVersion = r.Element("bver").Value.ToString(),
                                                  ClientId = r.Element("clid").Value.ToString(),
                                                  ExtId = r.Element("extid").Value.ToString(),
                                                  ExtType = r.Element("extype").Value.ToString(),
                                                  // Id = (string)r.Element("linksclicked"),
                                                  // Ip = (string)r.Element("linksclicked"),
                                                  // Location = (string)r.Element("linksclicked"),
                                                  OsVersion = r.Element("osver").Value.ToString(),
                                                  Platform = r.Element("ostype").Value.ToString(),
                                                  SysId = r.Element("sysid").Value.ToString()
                                              }).FirstOrDefault();
                UserInfo model = new UserInfo();
                db.Insert<UserInfo>(items);

            }
        }
開發者ID:riskypathak,項目名稱:NewTab,代碼行數:30,代碼來源:ExtensionController.cs

示例5: Load

        protected override void Load(ContainerBuilder builder)
        {
            OrmLiteConfig.DialectProvider = PostgreSQLDialectProvider.Instance;
            ServiceStack.OrmLite.OrmLiteConfig.DialectProvider.NamingStrategy = new LowercaseNamingStrategy();

            var connectionFactory = new OrmLiteConnectionFactory("Server=127.0.0.1;Port=5432;Database=transactions;User Id=postgres;Password=canada;", false, PostgreSqlDialect.Provider);

            using (var db = connectionFactory.OpenDbConnection())
            {
                DbSetup.Setup(db);
            }

            builder.Register(c => connectionFactory).As<IDbConnectionFactory>();
            builder.Register(c => connectionFactory.Open()).As<IDbConnection>().InstancePerLifetimeScope();

            builder.RegisterType<UserRepository>().As<IUserRepository>().As<IRepository<User>>().InstancePerLifetimeScope();
            builder.RegisterType<BudgetRepository>().As<IBudgetRepository>().As<IRepository<Budget>>().InstancePerLifetimeScope();
            builder.RegisterType<CategoryRepository>().As<ICategoryRepository>().As<IRepository<Category>>().InstancePerLifetimeScope();
            builder.RegisterType<TransactionRepository>().As<ITransactionRepository>().As<IRepository<Transaction>>().InstancePerLifetimeScope();

            //builder.RegisterType<UserRepository>().As<IRepository<User>>().InstancePerLifetimeScope();
            //builder.RegisterType<BudgetRepository>().As<IRepository<Budget>>().InstancePerLifetimeScope();
            //builder.RegisterType<CategoryRepository>().As<IRepository<Category>>().InstancePerLifetimeScope();
            //builder.RegisterType<TransactionRepository>().As<IRepository<Transaction>>().InstancePerLifetimeScope();
            builder.RegisterType<BillRepository>().As<IBillRepository>().As<IRepository<Bill>>().InstancePerLifetimeScope();

            builder.RegisterType<RepositoryUnitOfWork>().As<IRepositoryUnitOfWork>().InstancePerLifetimeScope();

            builder.RegisterType<SimpleBudgetService>().As<ISimpleBudgetService>().InstancePerLifetimeScope();

            // make sure our mock provider is accessible through IVoiceProvider and MockProvider for when we need to fake validation for things.
            //builder.RegisterType<MockProvider>().As<IVoiceProvider>().As<MockProvider>().InstancePerLifetimeScope();
            //builder.RegisterType<VoiceCore>().As<IVoiceCore>().As<VoiceCore>().InstancePerLifetimeScope();
        }
開發者ID:josiahpeters,項目名稱:SimpleBudget,代碼行數:34,代碼來源:AutofacDataModule.cs

示例6: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     var pageSize = 8;
     var Index = Request["Index"];
     if (string.IsNullOrWhiteSpace(Index))
     {
         Index = "0";
     }
     var start = Convert.ToInt32(Index);
     var dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.AppSettings["dbConnStr"], MySqlDialect.Provider);
     var db = dbFactory.Open();
     List<allen_news> obj;
     if(start == 0)
     {
         obj = db.Select<allen_news>("select * from allen_news order by news_id desc limit 0,"+(pageSize*2).ToString());
     }
     else
     {
         obj = db.Select<allen_news>("select * from allen_news where news_id < "+start.ToString()+" order by news_id desc limit 0," + pageSize.ToString());
     }
     db.Close();
     db.Dispose();
     if (obj.Count < 1)
     {
         Response.Write("Sorry...我們不打算把不算“新”聞的內容提供給您,您收藏的內容可以在“我的收藏”中找到。");
         Response.End();
         return;
     }
     Response.Write(JsonConvert.SerializeObject(obj));
     Response.End();
 }
開發者ID:qcjxberin,項目名稱:DeveloperNews,代碼行數:31,代碼來源:ViewService.aspx.cs

示例7: Main

 static void Main(string[] args)
 {
     string ConnectionString = ConfigurationManager.ConnectionStrings["p2pfDB"].ConnectionString;
     var dbFactory = new OrmLiteConnectionFactory(ConnectionString, PostgreSQLDialectProvider.Instance);
     using (IDbConnection db = dbFactory.Open())
     {
         db.CreateTableIfNotExists<Investor>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Borrower>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor1>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor2>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor3>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor4>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor5>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor6>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor7>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor8>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor9>();
         Console.WriteLine(db.GetLastSql());
         db.CreateTableIfNotExists<Investor10>();
         Console.WriteLine(db.GetLastSql());
     }
 }
開發者ID:MaxGorshkov,項目名稱:Test,代碼行數:32,代碼來源:Program.cs

示例8: CreateDatabase

 public void CreateDatabase(bool recreate = false)
 {
     Operation = "Creating database";
     var dbconn = new OrmLiteConnectionFactory(Bootstrapper.NoDBConnectionString);
     using (var db = dbconn.Open())
     {
         if (recreate)
         {
             try
             {
                 db.ExecuteSql("DROP DATABASE CS431PROJECT;");
             }
             catch (Exception)
             {
                 // Log
                 throw;
             }
         }
         try
         {
             db.ExecuteSql("CREATE DATABASE CS431PROJECT;");
         }
         catch (Exception)
         {
             // Log
             throw;
         }
     }
     Status = "Probably succeeded";
 }
開發者ID:adamr5000,項目名稱:CS431_Project,代碼行數:30,代碼來源:AdminModel.cs

示例9: GetUsers_Test

		public void GetUsers_Test()
		{
			var request = new GetUsers
			{
				UserIds = new ArrayOfLong(1, 2),
				UserNames = new ArrayOfString("User3", "User4")
			};

			var factory = new OrmLiteConnectionFactory(
				InMemoryDb, false, SqliteDialect.Provider);

            using (var db = factory.Open())
			{
				db.DropAndCreateTable<User>();
				db.Insert(new User { Id = 1, UserName = "User1" });
				db.Insert(new User { Id = 2, UserName = "User2" });
				db.Insert(new User { Id = 3, UserName = "User3" });
				db.Insert(new User { Id = 4, UserName = "User4" });

				var handler = new GetUsersService { ConnectionFactory = factory };

				var response = (GetUsersResponse)handler.Execute(request);

				Assert.That(response.Users.Count, Is.EqualTo(4));
			}
		}
開發者ID:nunopimenta,項目名稱:ServiceStack.Examples,代碼行數:26,代碼來源:GetUsersTests.cs

示例10: Setup

 public void Setup()
 {
     _connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
     var dbFactory = new OrmLiteConnectionFactory(_connectionString, SqlServerDialect.Provider);
     _connection = dbFactory.Open();
     _connection.DropAndCreateTable<AzureTraceMessage>();
 }
開發者ID:MRCollective,項目名稱:AzureTraceListeners,代碼行數:7,代碼來源:AzureSqlTraceListenerTests.cs

示例11: Index

 public ActionResult Index(string msg)
 {
     ViewBag.Message = msg;
     ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider);
     using (IDbConnection db = dbFactory.Open())
     {
         ViewBag.GroupList = db.Select<Group>().ToList();
     }
     return View();
 }
開發者ID:riskypathak,項目名稱:Poster,代碼行數:10,代碼來源:BulkImportController.cs

示例12: Database

        public void Database()
        {
            IDbConnectionFactory dbFactory =
                new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider);

            using (IDbConnection db = dbFactory.Open())
            {
                db.DropAndCreateTable<SessionDetail>();
                db.DropAndCreateTable<UserInfo>();
                db.DropAndCreateTable<UserTrack>();
            }
        }
開發者ID:riskypathak,項目名稱:NewTab,代碼行數:12,代碼來源:Initializer.cs

示例13: InMemoryDbBase

        public InMemoryDbBase()
        {
            b = new OrmLiteConnectionFactory(":memory:", SqliteOrmLiteDialectProvider.Instance, true);
            b.AutoDisposeConnection = false;

            using (var db = b.Open())
            {
                db.DropAndCreateTable<Movie>();
                db.DropAndCreateTable<Customer>();
                db.DropAndCreateTable<Showing>();
                db.DropAndCreateTable<Purchase>();
                db.DropAndCreateTable<Promotion>();
            }
        }
開發者ID:GeorgeHahn,項目名稱:CS431_Project,代碼行數:14,代碼來源:InMemoryDbBase.cs

示例14: SaveTwitterInfo

        private void SaveTwitterInfo(Profile model)
        {
            ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider);
            using (IDbConnection db = dbFactory.Open())
            {
                //Check user Exits
                var alreadyExist = db.Select<Profile>().Where(u => u.UserId == model.UserId).FirstOrDefault();
                if (alreadyExist != null)
                {
                    return;
                }
                db.Insert<Profile>(model);

            }
        }
開發者ID:riskypathak,項目名稱:Poster,代碼行數:15,代碼來源:TwitterController.cs

示例15: Delete

 public ActionResult Delete(int id = 0)
 {
     try
     {
         ServiceStack.Data.IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["db"].ConnectionString, MySqlDialect.Provider);
         using (IDbConnection db = dbFactory.Open())
         {
             db.DeleteById<Profile>(id);
         }
         return RedirectToAction("Index");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
開發者ID:riskypathak,項目名稱:Poster,代碼行數:16,代碼來源:ProfileController.cs


注:本文中的ServiceStack.OrmLite.OrmLiteConnectionFactory.Open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。