-
Notifications
You must be signed in to change notification settings - Fork 5
Home
FluentSql was designed with the goal of writing Sql like statements using C#. Therefore, if you know how to write your sql statements, then you will be able to write them in C# with no problem. For instance, take a look at a two join query:
var selectQuery = store.GetSelectQuery<Employee>()
.JoinOn<Order>((e, o) => e.Id == o.EmployeeId && o.Id >= 1)
.JoinOn<Order, Customer>((o, c) => o.CustomerId == c.Id)
.Where<Order, Customer, Employee>((o, c, e) => o.OrderDate > startingOrderDate
&& c.City == "Gainesville" && e.Id >= 1)
.OrderBy(e => e.Username);
FluentSql was also designed to save coding time by relying on the database schema information to make the proper Sql statements. Having this information cached at runtime, it makes sure to write the correct Sql statements the first time around. There is no need to add attributes to your models and keep up with its maintenance every time the database schema changes. FluentSql relies on the DatabaseMapper class to map all the tables and columns in a database. Currently, it supports Sql Server, and in time, it will support other database providers.
After mapping the database, it searches for the model types and matches the table names with the model type names. it uses the PluralizationService to help with the name matching. This information is cached in a Dictionary<Type, EntityMap>, and it is used at runtime to create the appropriate Sql statements. This Dictionary is exposed via the static class EntityMapper.Entities
Working with FluentSql is accomplished via the EntityStore class. It provides all the CRUD operations, sql statement creation, and store procedure execution. Please refer to the test project to see the different examples.