BIA.Net.Model
2.5.0
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
<PackageReference Include="BIA.Net.Model" Version="2.5.0" />
paket add BIA.Net.Model --version 2.5.0
#r "nuget: BIA.Net.Model, 2.5.0"
// 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 | Versions 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. |
-
- BIA.Net.Common (>= 1.8.0.1)
- EntityFramework (>= 6.1.3)
- log4net (>= 2.0.5)
- System.Linq.Dynamic (>= 1.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.