MicroEntities 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MicroEntities --version 0.0.1
                    
NuGet\Install-Package MicroEntities -Version 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="MicroEntities" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MicroEntities" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MicroEntities" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MicroEntities --version 0.0.1
                    
#r "nuget: MicroEntities, 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.
#:package MicroEntities@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MicroEntities&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MicroEntities&version=0.0.1
                    
Install as a Cake Tool

MicroEntities

MicroEntities are generic CRUD (Create Read Update Delete) templates used to rapidly develop and configure multi-tiered applications.

Creation and Configuration

Create a SQL Server data layer for object 'User' using table 'Users' for storage, and has methods Create, Select, Update, and Delete:

var dataLayer = new SqlServerSystemLayer<User>("server=[server_name];database=[database_name];Trusted_Connection=SSPI", "Users");

Create a validation layer for 'User' which validates the username, password, and balance fields:

var validationLayer = new FluentValidationLayer<User>(validator =>
{
	validator.RuleFor(user => user.UserName).Length(1, 50).Matches("^[a-zA-Z'., -]*$");
	validator.RuleFor(user => user.Password).Length(1, 50).Matches("^[a-zA-Z0-9]*$");
	validator.RuleFor(user => user.Balance).GreaterThanOrEqualTo(0);
});

Create a layer which benchmarks the underlying layers performance and logs the time take for each operation:

var benchmarkingLayer = new BenchmarkingLayer<User>();

Create a public layer which maps the internal object to one used for the public web service:

var userSystem = new PublicEntitySystem<UserDto, User>();

Create an entire stack for object 'User', with database, benchmarking and validation:

var userSystem = new PublicEntitySystem<UserDto, User>();

userSystem
.AddLayer(new BenchmarkingLayer<User>())
.AddLayer(new FluentValidationLayer<User>(validator =>
{
	validator.RuleFor(user => user.UserName).Length(1, 50).Matches("^[a-zA-Z'., -]*$");
	validator.RuleFor(user => user.Password).Length(1, 50).Matches("^[a-zA-Z0-9]*$");
	validator.RuleFor(user => user.Balance).GreaterThanOrEqualTo(0);
}))
.AddLayer(new SqlServerSystemLayer<User>("server=[computer_name];database=[database_name];Trusted_Connection=SSPI", "Users"));

Operations

Create a valid 'User' object via webservice:

[HttpPost]
public async Task<ActionResult> Create([FromBody] UserDto user)
{
	try
	{
		var result = await _userSystem.Create(user);
		return Ok(result);
	}
	catch (ArgumentException ex)
	{
		return BadRequest(ex.Message);
	}
	catch (Exception ex)
	{
		return StatusCode((int)HttpStatusCode.InternalServerError);
	}
}

Read a 'User' where 'Key' field is equal to 'key':

[HttpGet]
public async Task<ActionResult> Read(Guid key)
{
	try
	{
		var result = await _userSystem.Select(Where.Equal("Key", key ));
		return Ok(result);
	}
	catch (ArgumentException ex)
	{
		return BadRequest(ex.Message);
	}
	catch (Exception ex)
	{
		return StatusCode((int)HttpStatusCode.InternalServerError);
	}
}

Update an entire 'User' object:

[HttpPut("/edit")]
public async Task<ActionResult> EditUser([FromBody] UserDto user)
{
	try
	{
		var result = await _userSystem.Update(user, Where.Equal(nameof(user.Key), user.Key));
		return Ok(result);
	}
	catch (ArgumentException ex)
	{
		return BadRequest(ex.Message);
	}
	catch (Exception ex)
	{
		return StatusCode((int)HttpStatusCode.InternalServerError);
	}
}

Update a single property of the 'User' class as well as an auditing field:

[HttpPut("/edit/{key}/{property}/{value}")]
public async Task<ActionResult> Edit(string key, string property, string value)
{
	try
	{
		if (!property.Equals("Balance"))
		{
			var result = await _userSystem.Update(Set.Value(property, value).And("LastUpdatedOn", DateTime.Now), 
													Where.Equal("Key", key));
			return Ok(result);
		}
		else
		{
			var result = await _userSystem.Update(Set.Value(property, decimal.Parse(value)).And("LastUpdatedOn", DateTime.Now), 
													Where.Equal("Key", key));
			return Ok(result);
		}
	}
	catch (ArgumentException ex)
	{
		return BadRequest(ex.Message);
	}
	catch (Exception ex)
	{
		return StatusCode((int)HttpStatusCode.InternalServerError);
	}
}

Delete a user based on a field:

[HttpDelete]
public async Task<ActionResult> Delete(Guid value)
{
	try
	{
		await _userSystem.Delete(Where.Equal("Key", value));
		return Ok();
	}
	catch (ArgumentException ex)
	{
		return BadRequest(ex.Message);
	}
	catch (Exception ex)
	{
		return StatusCode((int)HttpStatusCode.InternalServerError);
	}
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows 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
0.0.4 228 5/3/2023
0.0.3 283 3/6/2023
0.0.2 280 3/2/2023
0.0.1 363 2/21/2023