First, to get an overview of the features of OrmLite, I recommend reading the documents on the OrmLite Home Page .
OrmLite ServiceStack, OrmLite NuGet, , InMemory, Sqlite NuGet:
Install-Package ServiceStack.OrmLite.Sqlite.Mono
* OrmLite.Sqlite.Mono Windows, Mono, Windows x86/x64 Sqlite OrmLite.Sqlite.Windows. SQL Server OrmLite.SqlServer .
, OrmLite ServiceStack, DB Factory RDBMS , :
public void Configure(Container container)
{
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
}
OrmLite POCO, 1:1 RDBMS, :
public class Simple
{
public int Id { get; set; }
public string Name { get; set; }
public int? Age { get; set; }
}
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<Simple>();
}
:
CREATE TABLE "Simple"
(
"Id" INTEGER PRIMARY KEY,
"Name" VARCHAR(8000) NULL,
"Age" INTEGER NULL
);
, , :
[Alias("CustomTable")]
public class Simple
{
[AutoIncrement]
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Alias("CustomAge")]
public int Age { get; set; }
}
SQL:
CREATE TABLE "CustomTable"
(
"Id" INTEGER PRIMARY KEY AUTOINCREMENT,
"Name" VARCHAR(100) NOT NULL,
"CustomAge" INTEGER NOT NULL
);
OrmLite API.
ServiceStack OrmLite ADO.NET Db Service. OrmLite POCO, , DTO ( DTO).
. ServiceStack Simple, Id, Simple:
public class MyServices : Service
{
public object Any(Simple request)
{
return request.Id != default(int)
? Db.SingleById<Simple>(request.Id)
: Db.Select<Simple>();
}
}
ServiceStack OrmLite, :