本文整理汇总了C#中ServiceStack.OrmLite.OrmLiteConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:C# OrmLiteConnectionFactory类的具体用法?C# OrmLiteConnectionFactory怎么用?C# OrmLiteConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OrmLiteConnectionFactory类属于ServiceStack.OrmLite命名空间,在下文中一共展示了OrmLiteConnectionFactory类的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: 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));
}
}
示例3: AddSiteProInfo
public void AddSiteProInfo(IEnumerable<SiteProInfo> siteList)
{
if (siteList == null) throw new ArgumentNullException("siteList");
_dbFactory = new OrmLiteConnectionFactory(ConnectionString, SqliteDialect.Provider);
using (var db = _dbFactory.OpenDbConnection())
{
try
{
db.InsertAll(siteList);
}
catch (Exception ex)
{
AddSitePro(siteList);
LogServer.WriteLog(ex, "DBError");
}
}
//var mmbdbFactory = new OrmLiteConnectionFactory(mmbpriceDBConnectionString, SqlServerDialect.Provider);
//using (var db = mmbdbFactory.OpenDbConnection())
//{
// try
// {
// db.CreateTable<SiteProInfo>();
// db.SaveAll(siteList);
// }
// catch (Exception ex)
// {
// LogServer.WriteLog(ex, "DBError");
// throw;
// }
//}
}
示例4: 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));
}
}
}
示例5: Configure
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
//Configure User Defined REST Paths
Routes.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name*}");
//Uncomment to change the default ServiceStack configuration
//SetConfig(new EndpointHostConfig {
//});
//Enable Authentication
//ConfigureAuth(container);
//IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(":memory:", false, SqliteOrmLiteDialectProvider.Instance);
IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(GetFileConnectionString(),
false, SqliteOrmLiteDialectProvider.Instance);
this.CreateSqliteInMemoryTables(dbFactory);
//string connectionString = ConfigurationManager.ConnectionStrings["ServiceStackTest"].ConnectionString;
//IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(connectionString, false, SqlServerOrmLiteDialectProvider.Instance);
container.Register<IDbConnectionFactory>(dbFactory);
//Register all your dependencies
container.Register(c => new TodoRepository(c.Resolve<IDbConnectionFactory>()));
}
示例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: CreateCompanyTable
public static void CreateCompanyTable(OrmLiteConnectionFactory factory)
{
using (IDbConnection db = factory.OpenDbConnection())
{
db.CreateTableIfNotExists<Company>();
}
}
示例8: Configure
public override void Configure(Container container)
{
//Permit modern browsers (e.g. Firefox) to allow sending of any REST HTTP Method
base.SetConfig(new EndpointHostConfig
{
GlobalResponseHeaders =
{
{ "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH" },
},
DefaultContentType = ContentType.Json
});
var config = new AppConfig(new ConfigurationResourceManager());
container.Register(config);
OrmLiteConfig.DialectProvider= FirebirdOrmLiteDialectProvider.Instance;
IDbConnectionFactory dbFactory = new OrmLiteConnectionFactory(
ConfigUtils.GetConnectionString("ApplicationDb"));
container.Register<Factory>(
new Factory(){
DbFactory=dbFactory
}
);
ConfigureAuth(container);
log.InfoFormat("AppHost Configured: " + DateTime.Now);
}
示例9: TestFixtureSetUp
public void TestFixtureSetUp()
{
_listeningOn = "http://localhost:1234/api/";
appHost = new TestAppHost
{
ConfigureContainer = container =>
{
var dbFactory = new OrmLiteConnectionFactory(
"Data Source=mydb.db;Version=3;", SqliteDialect.Provider);
container.Register<IDbConnectionFactory>(dbFactory);
container.RegisterAutoWiredAs
<PlacesToVisitRepository, IPlacesToVisitRepository>();
container.Register(new PlacesToVisitAppSettings());
var repo = container.Resolve<IPlacesToVisitRepository>();
repo.InitializeSchema();
_seedData.CreateUsers(container);
_seedData.SeedPlaces(repo);
},
ConfigureAppHost = host =>
{
host.Plugins.Add(new ValidationFeature());
host.Plugins.Add(new AuthFeature(() =>
new AuthUserSession(),
new IAuthProvider[] { new BasicAuthProvider() }));
}
}.Init().Start(_listeningOn);
}
示例10: AdminModule
public AdminModule(OrmLiteConnectionFactory db)
: base("/admin")
{
Get["/"] = _ =>
{
return View["AdminIndex"];
};
Get["/create/{recreate?}"] = _ =>
{
var admin = new AdminModel(db);
admin.CreateDatabase(_.recreate == "recreate");
admin.CreateTables();
return admin;
};
// Routes that hit the db should be async
// https://github.com/NancyFx/Nancy/wiki/Async
Get["/populatetestdata"] = _ =>
{
var admin = new AdminModel(db);
admin.PopulateTestData();
return admin;
};
}
示例11: ReFreshProList
public void ReFreshProList()
{
List<RegProListInfo> lits;
_dbFactory = new OrmLiteConnectionFactory(MmbpriceDbConnectionString, SqlServerDialect.Provider);
try
{
using (var db = _dbFactory.OpenDbConnection())
{
lits =
db.SqlList<RegProListInfo>(
"select 0 as id,siteid,urladdress as ProListUrl,listsReg,singleReg,UrlReg,PriceReg,TitleReg,PicReg,isSellReg,CommentCountReg,commentUrlReg,idReg as SkuReg,shopIDReg,maxpageReg,pageStart,pageStep,'' as Remark,getdate() as UpdateTime from JD_Reg_SiteList where [type]=0");
}
_dbFactory = new OrmLiteConnectionFactory(ConnectionString, SqliteDialect.Provider);
using (var db = _dbFactory.OpenDbConnection())
{
db.CreateTable<RegProListInfo>(true);
}
AddRegProList(lits);
}
catch (Exception ex)
{
LogServer.WriteLog(ex, "DBError");
throw;
}
}
示例12: GetOpenConnection
public static IDbConnection GetOpenConnection()
{
string connString = string.Empty;
IOrmLiteDialectProvider provider = null;
if (ConnectionString.StartsWith("postgres://"))
{
connString = GenerateConnectionStringForPostgreSQL(ConnectionString);
provider = PostgreSqlDialect.Provider;
}
else if (ConnectionString.StartsWith("sqlserver://"))
{
connString = GenerationConnectionStringForSqlServer(ConnectionString);
provider = SqlServerDialect.Provider;
}
else
{
connString = ConnectionString;
var providerString = config.Get("provider");
switch (providerString)
{
case "postgres":
provider = PostgreSqlDialect.Provider;
break;
case "sqlserver":
provider = SqlServerDialect.Provider;
break;
default:
break;
}
}
var dbFactory = new OrmLiteConnectionFactory(connString, provider);
return dbFactory.OpenDbConnection();
}
示例13: MetricService
public MetricService(string connectionString)
{
_factory = new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider);
_factory.Run(db => db.CreateTable<Metric>(overwrite: false));
_factory.Run(db => db.CreateTable<Message>(overwrite: false));
_factory.Run(db => db.CreateTable<Trend>(overwrite: false));
}
示例14: 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";
}
示例15: Init
public static void Init(Container container, string connectionString)
{
var dbConnectionFactory = new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider);
container.Register<IDbConnectionFactory>(dbConnectionFactory);
container.Register<ICacheClient>(new MemoryCacheClient());
//user auth testing
var userRepo = new InMemoryAuthRepository();
string hash;
string salt;
new SaltedHash().GetHashAndSaltString("ssapi", out hash, out salt);
userRepo.CreateUserAuth(new UserAuth
{
Id = 1,
DisplayName = "Api User",
Email = "[email protected]",
UserName = "ApiUser",
FirstName = "Api",
LastName = "User",
PasswordHash = hash,
Salt = salt
}, "ssapi");
container.Register<IUserAuthRepository>(userRepo);
}