CodeNet.EntityFramework 1.1.0

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

// Install CodeNet.EntityFramework as a Cake Tool
#tool nuget:?package=CodeNet.EntityFramework&version=1.1.0                

CodeNet.EntityFramework

CodeNet.EntityFramework is a .Net library.

Installation

Use the package manager npm to install CodeNet.EntityFramework

dotnet add package CodeNet.EntityFramework

Usage

appSettings.json

{
  "ConnectionStrings": {
    "SqlServer": "Data Source=localhost;Initial Catalog=TestDB;TrustServerCertificate=true"
  }
}

program.cs

using CodeNet.EntityFramework.Extensions;

var builder = WebApplication.CreateBuilder(args);
builder.AddSqlServer<CustomerDbContext>(builder.Configuration.GetConnectionString("SqlServer")!);
//or
builder.AddDbContext<CustomerDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("SqlServer")!));
//...

var app = builder.Build();
//...
app.Run();

DbContext

public partial class CustomerDbContext(DbContextOptions<CustomerDbContext> options) : DbContext(options)
{
    public virtual DbSet<Model.Customer> Customers { get; set; }
    public virtual DbSet<Employee> Employees { get; set; }
}

Repository

public class CustomerRepository(CustomerDbContext context, IIdentityContext identityContext) : 
    TracingRepository<Model.Customer>(context, identityContext), ICustomerRepository
{
}

Repository Usage

public class CustomerService(ICustomerRepository CustomerRepository, IAutoMapperConfiguration Mapper) : BaseService, ICustomerService
{
    public async Task<CustomerResponse> CreateCustomer(CreateCustomerRequest request, CancellationToken cancellationToken)
    {
        var model = Mapper.MapObject<CreateCustomerRequest, Model.Customer>(request);
        var result = await CustomerRepository.AddAsync(model, cancellationToken);
        await CustomerRepository.SaveChangesAsync(cancellationToken);
        return Mapper.MapObject<Model.Customer, CustomerResponse>(result);
    }

    public async Task<CustomerResponse> DeleteCustomer(int customerId, CancellationToken cancellationToken)
    {
        var result = await CustomerRepository.GetAsync([customerId], cancellationToken);
        CustomerRepository.Remove(result);
        await CustomerRepository.SaveChangesAsync(cancellationToken);
        return Mapper.MapObject<Model.Customer, CustomerResponse>(result);
    }

    public async Task<CustomerResponse?> GetCustomer(int customerId, CancellationToken cancellationToken)
    {
        var result = await CustomerRepository.GetAsync([customerId], cancellationToken) ?? throw new UserLevelException("01", "Kullanıcı bulunamadı!");
        return Mapper.MapObject<Model.Customer, CustomerResponse>(result);
    }

    public async Task<CustomerResponse> UpdateCustomer(UpdateCustomerRequest request, CancellationToken cancellationToken)
    {
        var result = await CustomerRepository.GetAsync([request.Id], cancellationToken);
        result.Code = request.Code;
        result.Description = request.Description;
        result.Name = request.Name;
        result.No = request.No;
        CustomerRepository.Update(result);
        await CustomerRepository.SaveChangesAsync(cancellationToken);
        return Mapper.MapObject<Model.Customer, CustomerResponse>(result);
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on CodeNet.EntityFramework:

Package Downloads
CodeNet.Identity

CodeNet Identity package.

CodeNet.EntityFramework.InMemory

CodeNet Entity Framework In Memory package.

CodeNet.EntityFramework.Sqlite

CodeNet Entity Framework PostgreSQL package.

CodeNet.EntityFramework.Oracle

CodeNet Entity Framework PostgreSQL package.

CodeNet.EntityFramework.MySQL

CodeNet Entity Framework MySQL package.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1-preview1 135 10/29/2024
1.1.0 177 9/25/2024