BIA.Net.Model 2.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package BIA.Net.Model --version 2.5.0                
NuGet\Install-Package BIA.Net.Model -Version 2.5.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="BIA.Net.Model" Version="2.5.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BIA.Net.Model --version 2.5.0                
#r "nuget: BIA.Net.Model, 2.5.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 BIA.Net.Model as a Cake Addin
#addin nuget:?package=BIA.Net.Model&version=2.5.0

// Install BIA.Net.Model as a Cake Tool
#tool nuget:?package=BIA.Net.Model&version=2.5.0                

BIA.Net.Model

Overview

The package BIA.Net.Model contains mainly the class:

  • TGenericRepository<Entity, ProjectDBContext>
  • TDBContainer< ProjectDBContext >
  • TGenericTransaction< ProjectDBContext >

Those classes offer advanced functionnalities for entity framework:

  • Four filters context (All, Read, Write, Delete)
  • Standard manipulation function.

It requiered to have an entityframework model.

Usage of TGenericRepository and TDBContainer

⇒ In your project create an entityframework model change the template who generate entity classe to make inherit this classes of ObjectRemap. Sample here.

  • in following sample the name of the Entity Container is : ZZProjectNameZZDBContainer

⇒ The TDBContainer should be referenced by unity. Place the folowing code in unity config :

BIAUnity.RegisterType<TDBContainer<ZZProjectNameZZDBContainer>, TDBContainer<ZZProjectNameZZDBContainer>>();

⇒ Acces to the repository and entity elements :

/// Create a repository based on an Entity Classe (here: MyEntity) 
TGenericRepository<MyEntity, ZZProjectNameZZDBContainer> Repository = new TGenericRepository<MyEntity, ZZProjectNameZZDBContainer>();;

... Initialization option ....
/// Acces to element
IQueryable<MyEntity> query = Repository.GetStandardQuery();
List<MyEntity> list = query.ToList();

⇒ Use Context filter :

You can use context filter to filter elements that can be read, update, delete. There is 4 filters property in the classe GenericRepository<Entity> :

  • Expression<Func<Entity, bool>> FilterContextAll (if not define return all) ⇒ corresponding access flag : AccessMode.All
  • Expression<Func<Entity, bool>> FilterContextRead (= FilterContextAll if not define) ⇒ corresponding access flag : AccessMode.Read
  • Expression<Func<Entity, bool>> FilterContextWrite (= FilterContextRead if not define) ⇒ corresponding access flag : AccessMode.Write
  • Expression<Func<Entity, bool>> FilterContextDelete (= FilterContextDelete if not define) ⇒ corresponding access flag : AccessMode.Delete

After the creation of the repository you can define tose filter, by using a Linq expression (this expression should be base on relations of your Entity ) ex :

Repository.FilterContextRead = s => s.Members.Any(m => m.AspNetUser.Id == userId);
Repository.FilterContextWrite = s => s.Members.Any(m => m.AspNetUser.Id == userId && m.MemberRole.Any(mr => mr.Id == Constants.MemberRoleSiteAdmin));

Now when you get the query you will have a different result, depending on the flag you passe in parameter:

IQueryable<MyEntity> query = Repository.GetStandardQuery(AccessMode.Read);
List<MyEntity> list = query.ToList();   => This return the list of all element filter by FilterContextRead

-----------------------------------------------

IQueryable<MyEntity> query = Repository.GetStandardQuery(AccessMode.Write);
List<MyEntity> list = query.ToList();   => This return the list of all element filter by FilterContextWrite

...

⇒ Standard manipulation function

  • Entity Insert(Entity entity, GenericRepositoryParmeter param = null) ⇒ insert an element ex:
MyEntity entity = new MyEntity();
entity.Name = "MyName";
MyEntity entityInsered = Repository.Insert(entity);
  • Entity UpdateValues(Entity entity, List<string> valuesToUpdate); ⇒ update a list of values in the entity, ONLY if the entity match with "FilterContextWrite" :
MyEntity entity = new MyEntity ();
entity.Name = "MyNewName";
MyEntity entityUpdated = Repository.UpdateValues(entity, new List<string>() { nameof(MyEntity.Name) });
 System.Diagnostics.Debug.Assert(entityUpdated != null, "Cannot update value");

• int DeleteById(object primaryKey, GenericRepositoryParmeter param = null); ⇒ delete an entity find by its primary keys, ONLY if the entity match with "FilterContextDelete" :

int id = 1;
int ret = Repository.DeleteById(id);
System.Diagnostics.Debug.Assert(ret == 0, "Cannot delete value");

⇒ Begin insert id at a specific value

If the key of your entity is not in automatic increment, the id will be generated based on the min value in the liste +1. You can use the option MinInsertKeysValue to begin at a specific number:

MyEntity entity = new MyEntity();
entity.Name = "MyName";
Repository.MinInsertKeysValue = 10000;
MyEntity entityInsered = Repository.Insert(entity);
  • ListInclude

  • GenericRepositoryParmeter param

Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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
2.5.0.3 200 5/17/2023
2.5.0.2 680 11/28/2019
2.5.0.1 618 9/12/2019
2.5.0 551 9/11/2019
1.9.1 623 5/13/2019
1.9.0 816 11/14/2018
1.8.0.4 815 9/19/2018
1.8.0.3 896 9/13/2018
1.8.0.2 976 7/4/2018
1.8.0.1 945 6/19/2018
1.8.0 990 5/14/2018
1.7.2 1,025 1/30/2018