Skip to content

Latest commit

 

History

History
84 lines (72 loc) · 3.51 KB

README.md

File metadata and controls

84 lines (72 loc) · 3.51 KB

Database-And-Queries

Repository and Unit of Work Pattern and Implementing Generic Repository in ASP.NET MVC using Fluent NHibernate.
Right now we written the library in C# , working for VB also , will release soon.

The following the are the features of the library:
a) User Can easily connect to any database due to Fluent NHibernate ORM
b) Already tested with MsSql2005,MsSql2008,MsSql2012,MYSQL,SQLITE. Working with ORACLE,POSTGRESQL.
c) Dont have to create the Mapping File, we implemented the AutoMapping, just have to create the class according tables.


Technical Specifications:

As you can see, there are two classes :

  1. Queries.cs
  2. SessionFactory.cs

SessionFactory.cs:
This is the Main File or Configuration File , We have to set the Few Paramters here to Connect the Database
like Hostname,Database Name, Database password , Database Type (which we have to use like Mysql,MS sql etc.)
To make the AutoMapping : have to set True or False, if true , have to provide the NameSpace of Models (where we put the classes)
Parameters
DatabaseName : Name of the database.
DatabaseHost : Ip or Domain name of host of database.
DatabaseUser : Username of the database
DatabasePassword : Password of the database.
AssemblyName : We have to Provide the name of the Assembly , where the models is placed.
NameSpaceM : Namespace of the Models only (if Automapping is true then only).
AutoMapping : True or False

Queries.cs :
In this file we write the Complete queries for CRUD operations and also with Multiple Conditions ,Order By, Sort By etc.
You can see the example in Attached Example Project.

Example With Mysql

We created the Windows Desktop for Example, we put the code in Program.cs, we have to initialize on Start of project.

DatabaseAndQueries.SessionFactory.DatabaseType = DatabaseAndQueries.DBTYPE.MySql.ToString();
DatabaseAndQueries.SessionFactory.DatabaseHost = "localhost";
DatabaseAndQueries.SessionFactory.DatabaseName = "TestGithub";
DatabaseAndQueries.SessionFactory.DatabasePassword = "123456";
DatabaseAndQueries.SessionFactory.DatabaseUser = "root";
DatabaseAndQueries.SessionFactory.NameSpaceM = "Example.Models";
DatabaseAndQueries.SessionFactory.AutoMapping = true;
DatabaseAndQueries.SessionFactory.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().ToString();


Insert data in to table
-----------------------
User _user = new User();
_user.Name = textBox1.Text;
Queries.Add<User>(_user);


Delete the data
------------
Queries.Delete<User>(_user);

Get Data by Condition
--------------------
Queries.GetDataByCondition<User>(x => x.Name == "John doe");

Retrieve all Rows from database
-------------------------------
Queries.GetAllData<User>();

Update the particular Row
---------------------------
Queries.Update<User>(_user);

Check the data exists or not
--------------------------------
Queries.IsExists<User>(x => x.Name == "John doe");