bs.Data
2.0.0
See the version list below for details.
dotnet add package bs.Data --version 2.0.0
NuGet\Install-Package bs.Data -Version 2.0.0
<PackageReference Include="bs.Data" Version="2.0.0" />
paket add bs.Data --version 2.0.0
#r "nuget: bs.Data, 2.0.0"
// Install bs.Data as a Cake Addin #addin nuget:?package=bs.Data&version=2.0.0 // Install bs.Data as a Cake Tool #tool nuget:?package=bs.Data&version=2.0.0
bs.Data
Nhibernate based repository using Fluent Nhibernate.
Install
Nuget
Install-Package bs.Data -Version 2.0.0
Configuration
Example config for Sqlite database:
private static IUnitOfWork CreateUnitOfWork_Sqlite()
{
var dbContext = new DbContext
{
ConnectionString = "Data Source=.\\bs.Data.Test.db;Version=3;BinaryGuid=False;",
DatabaseEngineType = "sqlite",
Create = true,
Update = true,
LookForEntitiesDllInCurrentDirectoryToo = true
};
var uOW = new UnitOfWork(dbContext);
return uOW;
}
Example config for MySql database:
private static IUnitOfWork CreateUnitOfWork_Mysql()
{
string server_ip = "localhost";
string server_port = "3307";
string database_name = "database";
string db_user_name = "root";
string db_user_password = "password";
var dbContext = new DbContext
{
ConnectionString = $"Server={server_ip};Port={server_port};Database={database_name};Uid={db_user_name};Pwd={db_user_password};SslMode=none",
DatabaseEngineType = "mysql",
Create = true,
Update = true,
LookForEntitiesDllInCurrentDirectoryToo = true
};
var uOW = new UnitOfWork(dbContext);
return uOW;
}
Models (entities)
Use Fluent Nhibernate to map your entities.
BaseEntity
Use BaseEntity class for normal entities. It implements Guid type Id field.
Example:
public class TestEntityModel : BaseEntity
{
public virtual string StringValue { get; set ; }
public virtual int IntValue { get; set ; }
public virtual DateTime DateTimeValue { get; set ; }
}
class TestEntityModelMap : SubclassMap<TestEntityModel>
{
public TestEntityModelMap()
{
// indicates that the base class is abstract
Abstract();
Table("TestEntity");
Map(x => x.StringValue);
Map(x => x.IntValue);
Map(x => x.DateTimeValue);
}
}
BaseAuditableEntity
Use BaseAuditableEntity class for auditable entities.
It implements Guid type Id field and DateTime? type CreationDate and LastUpdateDate fields.
The base repository will automatically populate the fields on creation and on update.
Example:
public class TestAuditableEntityModel : BaseAuditableEntity
{
public virtual string StringValue { get; set; }
public virtual int IntValue { get; set; }
public virtual DateTime DateTimeValue { get; set; }
}
class TestAuditableEntityModelMap : SubclassMap<TestAuditableEntityModel>
{
public TestAuditableEntityModelMap()
{
// indicates that the base class is abstract
Abstract();
Table("TestAuditableEntity");
Map(x => x.StringValue);
Map(x => x.IntValue);
Map(x => x.DateTimeValue);
}
}
Repository
Basic repository example
public class TestRepository : Repository
{
public TestRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
internal new void Create<T>(T entityToCreate) where T : IPersistentEntity
{
base.Create<T>(entityToCreate);
}
internal new T GetById<T>(Guid id) where T : IPersistentEntity
{
return base.GetById<T>(id);
}
internal new void Update<T>(T entity) where T : IPersistentEntity
{
base.Update<T>(entity);
}
internal new void Delete<T>(Guid id) where T : IPersistentEntity
{
base.Delete<T>(id);
}
}
Using Repository
public void TestRepositoryEntities()
{
IUnitOfWork uOW = CreateUnitOfWork(); //See the 'Configuration' chapter above...
var repository = new TestRepository(uOW); //See the 'Basic repository example' chapter above...
#region Create Entity
var entityToCreate = new TestEntityModel
{
DateTimeValue = DateTime.Now,
IntValue = 1,
StringValue = "Test"
};
using (var transaction = uOW.BeginTransaction())
{
repository.Create<TestEntityModel>(entityToCreate);
// Transaction autocommit or rollback if exception occurs when disposed.
}
#endregion
#region Retrieve Entity
var entity = repository.GetById<TestEntityModel>(entityToCreate.Id);
#endregion
#region Update Entity
var transaction = uOW.BeginTransaction()
entity.IntValue = 2;
entity.StringValue = "edited";
repository.Update(entity);
uOW.Commit(transaction); // simply commit (it can rise exceptions)
#endregion
#region Delete Entity
var transaction = uOW.BeginTransaction()
repository.Delete<TestEntityModel>(entity.Id);
uOW.TryCommitOrRollback(transaction); // It tries to commit but if error occurs it execute rollback
#endregion
uOW.Dispose();
}
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.0 is compatible. netcoreapp3.1 was computed. |
-
.NETCoreApp 3.0
- FluentNHibernate (>= 2.1.2)
- MySql.Data (>= 8.0.18)
- System.Data.SQLite.Core (>= 1.0.112)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on bs.Data:
Package | Downloads |
---|---|
bs.Frmwrk.Base
Package Description |
|
bs.Frmwrk.Security
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0.1 | 149 | 2/12/2024 |
5.0.0 | 242 | 12/3/2023 |
4.1.0 | 141 | 2/5/2024 |
4.0.4.5 | 198 | 11/7/2023 |
4.0.4.4 | 1,501 | 10/5/2023 |
4.0.4.2 | 570 | 9/12/2023 |
4.0.4.1 | 142 | 6/22/2023 |
4.0.4 | 250 | 2/9/2023 |
4.0.3 | 2,910 | 2/9/2023 |
4.0.2 | 257 | 2/9/2023 |
4.0.1 | 255 | 2/8/2023 |
4.0.0 | 546 | 2/7/2023 |
3.2.9 | 3,157 | 10/4/2021 |
3.2.8 | 488 | 8/2/2021 |
3.2.7 | 422 | 8/2/2021 |
3.2.6 | 457 | 7/27/2021 |
3.2.5 | 538 | 6/30/2021 |
3.2.4 | 511 | 5/6/2021 |
3.2.3 | 399 | 4/21/2021 |
3.2.2 | 437 | 4/12/2021 |
3.2.1 | 385 | 4/6/2021 |
3.2.0 | 399 | 4/2/2021 |
3.1.0 | 415 | 2/16/2021 |
3.0.6 | 387 | 12/29/2020 |
3.0.5 | 417 | 12/29/2020 |
3.0.4 | 501 | 9/4/2020 |
3.0.3 | 500 | 9/4/2020 |
3.0.2 | 508 | 9/3/2020 |
3.0.1 | 515 | 9/3/2020 |
3.0.0 | 524 | 9/2/2020 |
2.2.2 | 519 | 7/3/2020 |
2.2.1 | 527 | 7/2/2020 |
2.2.0 | 476 | 7/2/2020 |
2.1.3 | 470 | 7/1/2020 |
2.1.2 | 525 | 7/1/2020 |
2.1.1 | 517 | 6/17/2020 |
2.0.0 | 568 | 1/13/2020 |
1.2.0 | 608 | 11/11/2019 |