本文整理匯總了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();
}
示例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);
}
}
示例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));
}
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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());
}
}
示例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";
}
示例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));
}
}
示例10: Setup
public void Setup()
{
_connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
var dbFactory = new OrmLiteConnectionFactory(_connectionString, SqlServerDialect.Provider);
_connection = dbFactory.Open();
_connection.DropAndCreateTable<AzureTraceMessage>();
}
示例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();
}
示例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>();
}
}
示例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>();
}
}
示例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);
}
}
示例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;
}
}