Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

tamerfahmy/XDataAccess

Repository files navigation

xDataAccess

WhatIs((x, DataAccess) => { x = "Generic"; DataAccess = "Data Access Layer"; });

xDataAccess is an open-source cross-platform framework to dynamically build quires from lambda expression up to providing a complete data access layer for different data sources from the query generation up to the execution and data manipulation. It is Generic and extensible with different data source dialects.

Libraries

Project Pipeline Status Latest Release
XDataAccess.QueryBuilder Build Status v0.1.0 Preview

Features

  • Query Generation
    • Sql Server dialect
    • Oracle dialect
    • MySql dialect
    • Postgres dialect

How to Use

Models
public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
}

[Entity("dbo.employee")]
public class EmployeeWithAttributes
{
    [Identity]
    public int Id { get; set; }

    [PropertyAttribute("name")]
    public string Name { get; set; }

    [Ignore]
    public DateTime CreateDate { get; set; }
}
XDataAccess.QueryBuilder
var compiler = new SqlServerCompiler();
var builder = new QueryBuilder<EmployeeWithAttributes>(compiler);
Select
var output1 = builder.Select() as DbCompileResult; 
// "SELECT * FROM dbo.employee"

var output2 = builder.Select(e => (e.Id == 1 && e.Name == "value1") || e.Name != "value2") as DbCompileResult; 
// "SELECT * FROM dbo.employee WHERE ((([Id] = @P0) AND ([name] = @P1)) OR ([name] <> @P2))"

var output3 = builder.Select(e => e.Name == null) as DbCompileResult; 
// "SELECT * FROM dbo.employee WHERE ([name] IS NULL)"

var output4 = builder.Select(e => e.Name.Contains ("test")) as DbCompileResult; 
// "SELECT * FROM dbo.employee WHERE ([name] LIKE '%' + @P0 + '%')"
Update
var employeeToUpdate = new EmployeeWithAttributes() { Id = 1, Name = "test" };
var result = builder.Update(employeeToUpdate) as DbCompileResult; 
// "UPDATE dbo.employee SET [name] = @P0 WHERE [Id] = @P1"
Or
var result = builder.Update(employeeToUpdate, e => e.Id == 1) as DbCompileResult; 
// "UPDATE dbo.employee SET [name] = @P0 WHERE ([Id] = @P1)"
Delete
var result = builder.Delete (e => e.Id == 1) as DbCompileResult; 
// "DELETE FROM Employee WHERE ([Id] = @P0)"
Insert
var employee = new Employee() { Id = 1, Name = "Employee Name" };
var result = builder.Insert(employee) as DbCompileResult; 
// "INSERT INTO Employee ([Id],[Name]) VALUES (@P0,@P1)"