FluentFramework 2.2.1

FluentFramework is a nHibernate based object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects.

Install-Package FluentFramework -Version 2.2.1
dotnet add package FluentFramework --version 2.2.1
<PackageReference Include="FluentFramework" Version="2.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentFramework --version 2.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Implementation

  1. Create an implementation as like below and configure your connection. You can use different database connections instead of SQLite of course! Others are in FluentNHibernate.Cfg.Db namespace.
public class DefaultConnection : IConnectionConfigurer
{
    public IPersistenceConfigurer Configuration()
    {
        return SQLiteConfiguration.Standard.ConnectionString("Data Source=Database.db;Version=3;");
    }
}
  1. Adding configuration to service example.
public partial class App : Application
{
    public App()
    {
        ConnectionDescriptors.Add<DefaultConnection>(true, false, false);
    }
}
  1. Entity example;
public class Book : Entity<DefaultConnection>
{
    public virtual string Name { get; set; }
    public virtual User User { get; set; }

    public override bool OnPreInsert()
    {
        return Name != "maybe a banned word check?"; //cancel
    }

    public override bool OnPreUpdate()
    {
        return true;
    }

    public override bool OnPreDelete()
    {
        return true;
    }
}
  1. Mapping example;
public class BookMap : EntityMap<Book, DefaultConnection>
{
    public BookMap()
    {
        Map(x => x.Name).Not.Nullable();
        References(x => x.User).Not.Nullable();
    }
}
  1. Query example;
public User GetUser(string username)
{
    using (var repository = new Repository<DefaultConnection>())
    {
        return repository.Query<User>().Where(x => x.Username == username).SingleOrDefault();
    }
}
  1. Transaction example;
public void AddBook(string bookName, User user)
{
    using (var repository = new Repository<DefaultConnection>())
    {
        repository.Transaction.Begin();
        var book = new Book { Name = bookName, User = user };
        repository.Add(book);
        repository.SaveChanges();
    
        if(!doSomethingWithBook(book))
        {
            repository.Transaction.Rollback();
        }
    }
}

Examine the project to see what you can do more.

Features

  • Caching
  • Multiple ways of ID generation such as Identity, Sequence, HiLo, GUID, Pooled, and the Native mechanism used in databases. Uses Native by default.
  • Lazy Loading
  • Generation and updating system like migration API in Entity framework.
  • Cryptography helper for hashing and verifying passwords.
  • JSON entity serialization
  • Multiple database connections
  • Multiple database providers
    • SQL Server
    • SQL Server Azure
    • Oracle
    • PostgreSQL
    • MySQL
    • SQLite
    • DB2
    • Sybase Adaptive Server
    • Firebird
    • Informix
    • It can even support the use of OLE DB (Object Linking and Embedding) and ODBC (Open Database Connectivity).

Implementation

  1. Create an implementation as like below and configure your connection. You can use different database connections instead of SQLite of course! Others are in FluentNHibernate.Cfg.Db namespace.
public class DefaultConnection : IConnectionConfigurer
{
    public IPersistenceConfigurer Configuration()
    {
        return SQLiteConfiguration.Standard.ConnectionString("Data Source=Database.db;Version=3;");
    }
}
  1. Adding configuration to service example.
public partial class App : Application
{
    public App()
    {
        ConnectionDescriptors.Add<DefaultConnection>(true, false, false);
    }
}
  1. Entity example;
public class Book : Entity<DefaultConnection>
{
    public virtual string Name { get; set; }
    public virtual User User { get; set; }

    public override bool OnPreInsert()
    {
        return Name != "maybe a banned word check?"; //cancel
    }

    public override bool OnPreUpdate()
    {
        return true;
    }

    public override bool OnPreDelete()
    {
        return true;
    }
}
  1. Mapping example;
public class BookMap : EntityMap<Book, DefaultConnection>
{
    public BookMap()
    {
        Map(x => x.Name).Not.Nullable();
        References(x => x.User).Not.Nullable();
    }
}
  1. Query example;
public User GetUser(string username)
{
    using (var repository = new Repository<DefaultConnection>())
    {
        return repository.Query<User>().Where(x => x.Username == username).SingleOrDefault();
    }
}
  1. Transaction example;
public void AddBook(string bookName, User user)
{
    using (var repository = new Repository<DefaultConnection>())
    {
        repository.Transaction.Begin();
        var book = new Book { Name = bookName, User = user };
        repository.Add(book);
        repository.SaveChanges();
    
        if(!doSomethingWithBook(book))
        {
            repository.Transaction.Rollback();
        }
    }
}

Examine the project to see what you can do more.

Features

  • Caching
  • Multiple ways of ID generation such as Identity, Sequence, HiLo, GUID, Pooled, and the Native mechanism used in databases. Uses Native by default.
  • Lazy Loading
  • Generation and updating system like migration API in Entity framework.
  • Cryptography helper for hashing and verifying passwords.
  • JSON entity serialization
  • Multiple database connections
  • Multiple database providers
    • SQL Server
    • SQL Server Azure
    • Oracle
    • PostgreSQL
    • MySQL
    • SQLite
    • DB2
    • Sybase Adaptive Server
    • Firebird
    • Informix
    • It can even support the use of OLE DB (Object Linking and Embedding) and ODBC (Open Database Connectivity).

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FluentFramework:

Package Downloads
FluentFramework.Observing
FluentFramework.Observing is a helper tool to make database observing easy.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.1 223 1/16/2020
2.1.8 121 12/8/2019
2.1.7 108 12/8/2019
2.1.6 130 11/24/2019
2.1.4 235 9/18/2019
2.1.1 137 9/13/2019
1.2.4 206 9/13/2019