DbModelFramework.AspNetCore 1.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DbModelFramework.AspNetCore --version 1.6.0                
NuGet\Install-Package DbModelFramework.AspNetCore -Version 1.6.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DbModelFramework.AspNetCore" Version="1.6.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DbModelFramework.AspNetCore --version 1.6.0                
#r "nuget: DbModelFramework.AspNetCore, 1.6.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DbModelFramework.AspNetCore as a Cake Addin
#addin nuget:?package=DbModelFramework.AspNetCore&version=1.6.0

// Install DbModelFramework.AspNetCore as a Cake Tool
#tool nuget:?package=DbModelFramework.AspNetCore&version=1.6.0                

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.6.3 161 4/7/2024
1.6.0 428 12/29/2020