FluentNHibernate.DAL 1.0.1

dotnet add package FluentNHibernate.DAL --version 1.0.1
                    
NuGet\Install-Package FluentNHibernate.DAL -Version 1.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="FluentNHibernate.DAL" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentNHibernate.DAL" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="FluentNHibernate.DAL" />
                    
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 FluentNHibernate.DAL --version 1.0.1
                    
#r "nuget: FluentNHibernate.DAL, 1.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.
#addin nuget:?package=FluentNHibernate.DAL&version=1.0.1
                    
Install FluentNHibernate.DAL as a Cake Addin
#tool nuget:?package=FluentNHibernate.DAL&version=1.0.1
                    
Install FluentNHibernate.DAL as a Cake Tool

FluentNHibernate.DAL

A robust and flexible Data Access Layer (DAL) built with FluentNHibernate, providing a generic repository pattern implementation with advanced querying capabilities and comprehensive database management features.

🚀 Features

  • Generic Repository Pattern: Complete CRUD operations with async/await support
  • Custom Repository Support: Easily extend base functionality for entity-specific operations
  • Code-First Approach: Start with C# classes and let the database be auto-generated
  • Auto Mapping: Automatic table and relationship creation from entity definitions
  • Advanced Querying: Support for custom SQL queries, pagination, and complex filtering
  • Batch Operations: Efficient bulk insert, update, and delete operations
  • Schema Management: Automated schema creation, updates, and validation
  • Migration Support: Database versioning and migration capabilities for keeping database in sync with code changes
  • Transaction Support: Built-in transaction handling and management
  • Fluent Configuration: Easy-to-use fluent API for entity mappings
  • Cross-Database Support: Works with multiple database providers (PostgreSQL, SQL Server, MySQL, etc.)

🎯 Development Approaches

FluentNHibernate.DAL supports both Code-First and Database-First development approaches, giving you flexibility to choose the workflow that best fits your project needs.

Code-First Approach

Start with C# entities and auto-generate database schema:

  1. Define entity classes and mappings
  2. Configure session factory with schema generation
  3. Database tables are created automatically

Benefits: Rapid prototyping, version-controlled schema, consistent across environments.

📖 Code-First Guides: Entity Mappings | Schema Generation

Database-First Approach

Work with existing databases by mapping to established schema:

  1. Connect to existing database
  2. Create entity classes matching database structure
  3. Define mappings that align with current schema

Benefits: Integration with legacy systems, preserve existing data, work with established database designs.

📖 Database-First Guides: Entity Mappings | Custom Repositories

📖 Learn More:

📋 Prerequisites

  • .NET Core 3.1 or higher
  • NHibernate 5.x or higher
  • A supported database (PostgreSQL, SQL Server, MySQL, SQLite, Oracle)

📦 Installation

NuGet Package Manager

Install-Package FluentNHibernate
Install-Package NHibernate

.NET CLI

dotnet add package FluentNHibernate
dotnet add package NHibernate

PackageReference

<PackageReference Include="FluentNHibernate" Version="3.1.0" />
<PackageReference Include="NHibernate" Version="5.4.6" />

🔧 Quick Start

1. Define Entity & Mapping

public class User
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Email { get; set; }
    public virtual bool IsActive { get; set; }
}

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("Users");
        Id(x => x.Id);
        Map(x => x.Name).Length(100).Not.Nullable();
        Map(x => x.Email).Length(100).Not.Nullable();
        Map(x => x.IsActive).Not.Nullable();
    }
}

📖 Learn More: Entity Definitions & Complex Relationships

2. Configure Session Factory

public static ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(PostgreSQLConfiguration.Standard.ConnectionString("your-connection-string"))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<User>())
        .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true)) // Auto-create tables
        .BuildSessionFactory();
}

📖 Learn More: Schema Generation & Management | Migration Strategies

3. Use Repository

var repository = new NHibernateRepository<User>(sessionFactory);
await repository.InsertAsync(new User { Name = "John Doe", Email = "john@example.com" });
var user = await repository.GetAsync(1);

📖 Learn More: Custom Repository Patterns

📖 Detailed Guides: Entity Mappings | Schema Management | Custom Repositories

📚 Documentation

Guide Description
Custom Repository Entity-specific operations and advanced repository patterns
Entities & Mappings Define entities, relationships, and complex mappings
Migrations Database versioning and schema evolution strategies
Schema Export Automated schema generation and management
NuGet Deployment Complete guide to building and deploying NuGet packages

🎯 Usage Examples

Basic Operations

var repository = new NHibernateRepository<User>(sessionFactory);

// CRUD operations
await repository.InsertAsync(new User { Name = "Alice", Email = "alice@example.com" });
var user = await repository.GetAsync(1);
await repository.UpdateAsync(user);
await repository.DeleteAsync(user);

// Filtering & pagination
var activeUsers = await repository.GetByAsync(u => u.IsActive);
var pagedUsers = await repository.GetBySQLAsync("SELECT * FROM Users WHERE IsActive = :active",
    new Dictionary<string, object> { { "active", true } }, 0, 10);

Custom Repository

public class UserRepository : NHibernateRepository<User>, IUserRepository
{
    public async Task<User> GetByEmailAsync(string email) =>
        await GetByAsync(u => u.Email == email);

    public async Task<int> GetActiveUserCountAsync() =>
        await GetCountByAsync(u => u.IsActive);
}

📖 More Examples: Custom Repository Guide | Entity Relationship Examples

🏗️ Architecture

FluentNHibernate.DAL/
├── Configuration/          # Database and session configuration
├── Infrastructure/         # Core repository implementations
├── Repositories/          # Custom repository implementations
├── Utils/                # Utility classes and helpers
└── docs/                 # Documentation files

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow C# coding conventions
  • Include unit tests for new features
  • Update documentation as needed
  • Ensure all tests pass before submitting PR

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • FluentNHibernate - The awesome ORM that makes this possible
  • NHibernate - The underlying ORM framework
  • Community contributors and testers

📞 Support


Made with ❤️ for the .NET community

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.  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
1.0.1 31 6/15/2025
1.0.0 37 6/15/2025

v1.0.1 - Initial release
     - Generic Repository Pattern with async/await support
     - Code-First and Database-First development approaches
     - Advanced querying with custom SQL support
     - Batch operations for efficient data processing
     - Cross-database support (PostgreSQL, SQL Server, MySQL, etc.)
     - Comprehensive documentation and examples