bs.Data 5.0.0.1

dotnet add package bs.Data --version 5.0.0.1
NuGet\Install-Package bs.Data -Version 5.0.0.1
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="bs.Data" Version="5.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add bs.Data --version 5.0.0.1
#r "nuget: bs.Data, 5.0.0.1"
#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 bs.Data as a Cake Addin
#addin nuget:?package=bs.Data&version=5.0.0.1

// Install bs.Data as a Cake Tool
#tool nuget:?package=bs.Data&version=5.0.0.1

bs.Data

Nhibernate based repository using Fluent Nhibernate.

Install

Nuget

 Install-Package bs.Data

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 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 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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 (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 107 2/12/2024
5.0.0 218 12/3/2023
4.1.0 85 2/5/2024
4.0.4.5 134 11/7/2023
4.0.4.4 1,005 10/5/2023
4.0.4.2 401 9/12/2023
4.0.4.1 114 6/22/2023
4.0.4 227 2/9/2023
4.0.3 2,245 2/9/2023
4.0.2 236 2/9/2023
4.0.1 234 2/8/2023
4.0.0 490 2/7/2023
3.2.9 2,866 10/4/2021
3.2.8 458 8/2/2021
3.2.7 396 8/2/2021
3.2.6 429 7/27/2021
3.2.5 514 6/30/2021
3.2.4 485 5/6/2021
3.2.3 368 4/21/2021
3.2.2 410 4/12/2021
3.2.1 364 4/6/2021
3.2.0 366 4/2/2021
3.1.0 388 2/16/2021
3.0.6 363 12/29/2020
3.0.5 396 12/29/2020
3.0.4 472 9/4/2020
3.0.3 473 9/4/2020
3.0.2 476 9/3/2020
3.0.1 488 9/3/2020
3.0.0 503 9/2/2020
2.2.2 492 7/3/2020
2.2.1 498 7/2/2020
2.2.0 452 7/2/2020
2.1.3 443 7/1/2020
2.1.2 493 7/1/2020
2.1.1 495 6/17/2020
2.0.0 541 1/13/2020
1.2.0 583 11/11/2019