FluentFramework 1.2.2

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 1.2.2
dotnet add package FluentFramework --version 1.2.2
<PackageReference Include="FluentFramework" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentFramework --version 1.2.2
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. Also you can expand and improve your FluentNHibernate configurations on here.
public class DefaultConnection : IConnectionDescriptive
{
    public FluentConfiguration Configuration(FluentConfiguration cfg, bool useSecondLevelCache, bool useQueryCache, out bool useDefaultCachingMechanism, out bool autoCreateDatabase)
    {
        autoCreateDatabase = true;
        useDefaultCachingMechanism = true;
        return cfg.Database(SQLiteConfiguration.Standard.ConnectionString("Data Source=Database.db;Version=3;"));
    }
}
  1. Create entities as like below;
public class Book : Entity<DefaultConnection>
{
    public virtual string Name { get; set; }
    public virtual User User { get; set; }
}
  1. Map your entity as like below;
public class BookMap : EntityMap<Book, DefaultConnection>
{
    public BookMap()
    {
        Map(x => x.Name).Not.Nullable();
        References(x => x.User).Not.Nullable();
    }
}
  1. Get your database connection as like below;
public User GetUser(string username)
{
    var repository = Repository<DefaultConnection>.CreateRepository();
    return repository.Query<User>().Where(x => x.Username == username).SingleOrDefault()
}
  1. You can also use transactions easy like below;
public void AddBook(string bookName, User user)
{
    var repository = Repository<DefaultConnection>.CreateRepository();
    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. Also you can expand and improve your FluentNHibernate configurations on here.
public class DefaultConnection : IConnectionDescriptive
{
    public FluentConfiguration Configuration(FluentConfiguration cfg, bool useSecondLevelCache, bool useQueryCache, out bool useDefaultCachingMechanism, out bool autoCreateDatabase)
    {
        autoCreateDatabase = true;
        useDefaultCachingMechanism = true;
        return cfg.Database(SQLiteConfiguration.Standard.ConnectionString("Data Source=Database.db;Version=3;"));
    }
}
  1. Create entities as like below;
public class Book : Entity<DefaultConnection>
{
    public virtual string Name { get; set; }
    public virtual User User { get; set; }
}
  1. Map your entity as like below;
public class BookMap : EntityMap<Book, DefaultConnection>
{
    public BookMap()
    {
        Map(x => x.Name).Not.Nullable();
        References(x => x.User).Not.Nullable();
    }
}
  1. Get your database connection as like below;
public User GetUser(string username)
{
    var repository = Repository<DefaultConnection>.CreateRepository();
    return repository.Query<User>().Where(x => x.Username == username).SingleOrDefault()
}
  1. You can also use transactions easy like below;
public void AddBook(string bookName, User user)
{
    var repository = Repository<DefaultConnection>.CreateRepository();
    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).

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.2.2 151 10/28/2018
1.2.1 136 9/20/2018