NPrismy 1.1.4
dotnet add package NPrismy --version 1.1.4
NuGet\Install-Package NPrismy -Version 1.1.4
<PackageReference Include="NPrismy" Version="1.1.4" />
paket add NPrismy --version 1.1.4
#r "nuget: NPrismy, 1.1.4"
// Install NPrismy as a Cake Addin
#addin nuget:?package=NPrismy&version=1.1.4
// Install NPrismy as a Cake Tool
#tool nuget:?package=NPrismy&version=1.1.4
NPrismy - A Lightweight .NET Core ORM Framework
NPrismy is lightweight ORM for ASP.NET Core Web Applications.
- Add MySql support
- Add Oracle Db support
- Add benchmark results
Table Of Contents
Features
- Simple CRUD operations with sugar syntax.
- Using database transactions
- Customized entity mappings
- Private field mapping support
- Managing persistance concerns with a high level language
Installation
Install NPrismy NuGet package by executing following command on .NET Core CLI:
dotnet add package NPrismy
and
PM> Install-Package NPrismy
on NuGet Package Manager Console.
Usage
Step by step initialization.
1) Create a Database class
Create a database class that inherited from NPrismy.Database abstract class. (i.e. CarFactoryDatabase) Database classes are represents the remote database. (Like EF DbContext)
public class WeatherForecastDatabase : NPrismy.Database
{
}
2) Add NPrismy support
Insert the following code to your Startup.cs ConfigureServices() method to register your database object to ServiceCollection.
services.AddNPrismy<WeatherForecastDatabase>()
.UseProvider(PersistanceProvider.SqlServer)
.ConnectionString("#your-connection-string#");
- Specify the connection string by passing it to
ConnectionString()
method. - Specify the your persistance provider (SqlServer, Oracle DB, MySql) by calling
UseProvider()
method. (ONLY MICROSOFT SQL SERVER SUPPORTED AT THE MOMENT)
3) Specify your tables
Add EntityTable<T>
properties to your database class to specify your database tables.
public class WeatherForecastDatabase : NPrismy.Database
{
public EntityTable<City> Cities { get; set; }
public EntityTable<Forecast> Forecasts { get; set; }
}
4) Specify table names and schemas (optional)
As default, NPrismy pluralizes the property types of database class. And assumes they are in the dbo
schema. In the above example, NPrismy assumes there are two different tables named dbo.Cities
and dbo.Forecasts
. Regardless of the names of properties, NPrismy pluralizes the types City
and Foreacast
.
If you override these definitions, simply put [TableName]
and [Schema]
attributes as following.
public class WeatherForecastDatabase : NPrismy.Database
{
[TableName("MyCities")]
[Schema("weatherForecast")]
public EntityTable<City> Cities { get; set; }
[TableName("AwesomeForecasts")]
[Schema("weatherForecast")]
public EntityTable<Forecast> Forecasts { get; set; }
}
5) Do your CRUD!
Modify your controllers as accepts WeatherForecastDatabase
(how you name it) and you're done. Querying data can be performed as following:
var lovelyCities = _db.Cities.Query(c => c.Name == "Istanbul" || c.Name == "Copenhagen");
Examples
Query Data
- Querying all data from table.
var cities = await _database.Cities.Query();
- Querying with where clause
var cities = await _database.Cities.Query(c => c.Name == 'Copenhagen');
- Getting by primary key
var city = await _database.Cities.FindByPrimaryKey(1); //Gets the city with ID '1' (or whatever the primary key)
Insert Data
var city = new City(name: "Paris", country: "FR");
_database.Cities.Add(city);
_database.Commit(); //Don't forget to commit
Update Data
var city = await _database.Cities.FindByPrimaryKey(10);
city.Name = "Paris";
_database.Cities.Update(city);
_database.Commit();
Delete Data
- Deleting with LINQ expression
_database.Cities.Delete(c => c.Name == "Copenhagen");
_database.Commit();
- Deleting by Primary Key
_database.Cities.Delete(1); //Deletes the city with ID 1
_database.Commit();
Entity Specifications
Note: All these following specifications must be applied on
EntityTable<T>
properties of your Database class.
Specifying table name
NOTE: NPrismy pluralizes the entity type as default table name. Use this attribute only you need a different name.
Table names can be specified with [TableName]
attribute.
Usage example:
[TableName("people")]
public EntityTable<AbstractPerson> People { get; set; }
According to the example above, specifying the table name as people
means your table name is dbo.people
instead of dbo.AbstractPeople
.
Specifying schema name
Schema name can be specified with [Schema]
attribute.
Usage example:
[Schema("usermanagement")]
public EntityTable<AbstractPerson> People { get; set; }
NOTE: NPrismy assumes
dbo
is the schema name as default. Use this specification only if your table schema is different fromdbo
.
Specifying primary key
Specify entity's primary key by using [PrimaryKey]
attribute.
Usage example:
[PrimaryKey("PolicyDefinitionId")]
[TableName("policies")]
public EntityTable<PolicyDefinition> Policies { get; set; }
NPrismy behaves the
Id
property of a entity as primary key as default. Use this specification only if your primary key column is different fromId
.
Mapping private properties
Ignoring properties
Enabling identity insert
Benchmark Results
I will fill up here.
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 | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Autofac (>= 6.0.0)
- Microsoft.Data.SqlClient (>= 2.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Newtonsoft.json (>= 12.0.3)
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.1.4 | 428 | 10/29/2020 |
1.1.3 | 363 | 10/28/2020 |
1.1.2 | 406 | 10/17/2020 |
1.1.1 | 360 | 10/17/2020 |
1.1.0 | 429 | 10/17/2020 |
1.0.9 | 446 | 10/17/2020 |
1.0.8 | 465 | 10/16/2020 |
1.0.7 | 457 | 10/16/2020 |
1.0.6 | 467 | 10/16/2020 |
0.9.8 | 380 | 10/16/2020 |
0.9.7 | 369 | 10/16/2020 |
0.9.6 | 378 | 10/16/2020 |
0.9.5 | 426 | 10/15/2020 |
0.9.4 | 407 | 10/14/2020 |
0.9.3 | 584 | 10/13/2020 |
0.9.2 | 587 | 10/13/2020 |
Added PrimaryKey attribute lets specify primary key of a specific entity, bug fixes.