FluentNHibernate.DAL
1.0.1
dotnet add package FluentNHibernate.DAL --version 1.0.1
NuGet\Install-Package FluentNHibernate.DAL -Version 1.0.1
<PackageReference Include="FluentNHibernate.DAL" Version="1.0.1" />
<PackageVersion Include="FluentNHibernate.DAL" Version="1.0.1" />
<PackageReference Include="FluentNHibernate.DAL" />
paket add FluentNHibernate.DAL --version 1.0.1
#r "nuget: FluentNHibernate.DAL, 1.0.1"
#addin nuget:?package=FluentNHibernate.DAL&version=1.0.1
#tool nuget:?package=FluentNHibernate.DAL&version=1.0.1
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:
- Define entity classes and mappings
- Configure session factory with schema generation
- 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:
- Connect to existing database
- Create entity classes matching database structure
- 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:
- Entity Definitions & Relationships - Complete guide for both approaches
- Schema Generation Options - Code-first schema management
- Database Migration Strategies - Evolution strategies for both approaches
📋 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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
- Create an Issue for bug reports or feature requests
- Check our Documentation for detailed guides
- Review Custom Repository Examples
- Learn about Database Migrations for production deployments
Made with ❤️ for the .NET community
Product | Versions 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. |
-
net8.0
- AutoMapper (>= 13.0.1)
- FluentNHibernate (>= 3.4.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- NHibernate (>= 5.5.2)
- NHibernateProfiler (>= 6.0.6047)
- NHibernateProfiler.Appender (>= 6.0.6047)
- Npgsql (>= 8.0.4)
- Polly (>= 8.4.1)
- Serilog (>= 4.0.1)
- Serilog.Sinks.Seq (>= 8.0.0)
- System.Configuration.ConfigurationManager (>= 8.0.0)
- System.Data.SqlClient (>= 4.8.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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