DbModelFramework 1.6.3
dotnet add package DbModelFramework --version 1.6.3
NuGet\Install-Package DbModelFramework -Version 1.6.3
<PackageReference Include="DbModelFramework" Version="1.6.3" />
paket add DbModelFramework --version 1.6.3
#r "nuget: DbModelFramework, 1.6.3"
// Install DbModelFramework as a Cake Addin #addin nuget:?package=DbModelFramework&version=1.6.3 // Install DbModelFramework as a Cake Tool #tool nuget:?package=DbModelFramework&version=1.6.3
DbModelFramework
Getting started
Environment
Download NuGet-Package
Inject InjectionContainer
As a minimum requirement you have to define a new injection container with at least a DbRequirements class as a part. You can use one of the predifined DbRequirements (DbModelFramework.Sqlite, DbModelFramework.MySql, DbModelFramework.MsSql). The DbRequirements class has to export the type DbModelFramework.DbRequirements.
Your DbRequirements class:
[Export(typeof(DbModelFramework.DbRequirements))]
class DbRequirements : DbModelFramework.Sqlite.DbRequirements
{
private static readonly string ConnectionString = new SqliteConnectionStringBuilder { DataSource = "database.db" }.ConnectionString;
public override IDbConnection CreateDbConnection()
{
var connection = new SqliteConnection(ConnectionString);
connection.Open();
return connection;
}
}
Injection container creation (System.Composition is required):
var configuration = new ContainerConfiguration();
configuration.WithPart<DbRequirements>();
DbModelFramework.DependencyInjection.InjectionContainer = configuration.CreateContainer();
Use the models
Define a new model class
class MyModel : Model<MyModel>
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
Create a new model instance (insert in db)
var myModel = MyModel.Create();
Get all model data
var myModels = MyModel.Get();
Get all model data which fits in the condition
var myModels = MyModel.Get(model => model.Property1 == "MyValue");
Get model data by primary key
var myModel = MyModel.Get(1); // Get model data with primary key 1
Save changes of a models data (update in db)
myModel.Save();
Delete model data (delete from db)
myModel.Delete();
Reload model data
myModel.Reload();
Advanced
Model-in-Model
class MyReferencedModel : Model<MyReferencedModel>
{
public string Property { get; set; }
}
class MyReferencingModel : Model<MyReferencingModel>
{
public MyReferencedModel ReferencedModel { get; set; }
}
Unique values
class MyUniqueValueModel : Model<MyUniqueValueModel>
{
[Unique]
public string UniqueProperty { get; set; }
}
Ignore values for db storage
class MyDbIgnoreModel : Model<MyDbIgnoreModel>
{
[DbIgnore]
public string NotSavedInDbProperty { get; set; }
public string SavedInDbProperty { get; set; }
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Composition (>= 6.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on DbModelFramework:
Package | Downloads |
---|---|
DbModelFramework.Sqlite
Pre-defined sqlite DbRequirements for DbModelFramework |
|
DbModelFramework.MsSql
Pre-defined MsSql DbRequirements for DbModelFramework |
|
DbModelFramework.MySql
Pre-defined MySql and MariaDb DbRequirements for DbModelFramework |
|
DbModelFramework.AspNetCore
DbModelFramework AspNetCore Extensions |
GitHub repositories
This package is not used by any popular GitHub repositories.