Simple ORM for C# possibiliting connect to MySql, Sql Server, MariaDB, Firebird, Postgree databases.
Conv.ORM is a simple ORM, designed to remove the need for a developer to deal with SQL commands, thus speeding up the development process and facilitating maintenance.
Yes, but not quite. Currently the following features are functional:
- MySql/MariaDB and MSSQL connection;
- Insert, Update and Search entities for DB mentioned above;
The full roadmap can be found in full here
- Delete entities;
- Inactivation entities;
- Full select commands;
- Full conditions for querys commands;
- Allow relationship between entities;
- Temporary entities;
- Read-only entities;
- Allow to custom events before and after executions;
- Support for Postgree;
- Support for Firebird;
- Support for SQLite;
Before you start, you will need to install it on your project:
Using dotnet cli
$ dotnet add package Conv.ORM
Using Nuget Package Manager
PM> Install-Package Conv.ORM
- Create a connection:
- Using connection file:
Connection connection = ConnectionFactory.GetConnection();
- Using specified parameters
ConnectionParameters connectionParameters = new ConnectionParameters("Default", EConnectionDriverTypes.ecdtMySql, "127.0.0.1", "3306", "databaseTest", "root", "123456");
Connection connection = ConnectionFactory.GetConnection(connectionParameters);
- Create a entity
[EntitiesAttributes(TableName = "User")]
public class UserEntity : Entity
{
[EntitiesColumnAttributes(
Primary = true,
Default = "0"
)]
public int UserId;
public string Name;
public string Login;
public string Password;
[EntitiesColumnAttributes(Default = "true")]
public bool Active;
}
- Create a manipulations methods
- Save
public UserEntity Save()
{
var userRepository = new Repository();
try
{
if (UserId != 0)
return (UserEntity)userRepository.Update(this);
else
return (UserEntity)userRepository.Insert(this);
}
catch(Exception ex)
{
Console.Write(ex.Message);
throw;
}
}
- Find All
public IList FindAll()
{
var userRepository = new Repository();
try
{
return userRepository.FindAll(this);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
- Find by conditions
public IList Find(QueryConditionsBuilder conditionsBuilder)
{
var userRepository = new Repository();
try
{
return userRepository.Find(this, conditionsBuilder);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
- Find by id
public UserEntity Find(int id)
{
var userRepository = new Repository();
try
{
return (UserEntity)userRepository.Find(this, new int[] {id});
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
- Searching
- For conditions to find registers, you can create a ConditionBuilder:
var queryConditions = new QueryConditionsBuilder();
queryConditions.AddQueryCondition("name", EConditionTypes.Like, new object[] {"%" + txtTextToSearch.Text + "%"});
queryConditions.AddQueryCondition("active", EConditionTypes.Equals, new object[] { rbOnlyActives.Checked ? 1 : 0 });
dgvRegisters.DataSource = ConvORMHelper.ConvertListToDataTable(userEntity.Find(queryConditions));
- 📚 For full documentation, go to here (In development)