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.
Project | Pipeline Status | Latest Release |
---|---|---|
XDataAccess.QueryBuilder | v0.1.0 Preview |
- Query Generation
- Sql Server dialect
- Oracle dialect
- MySql dialect
- Postgres dialect
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; }
}
var compiler = new SqlServerCompiler();
var builder = new QueryBuilder<EmployeeWithAttributes>(compiler);
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 + '%')"
var employeeToUpdate = new EmployeeWithAttributes() { Id = 1, Name = "test" };
var result = builder.Update(employeeToUpdate) as DbCompileResult;
// "UPDATE dbo.employee SET [name] = @P0 WHERE [Id] = @P1"
var result = builder.Update(employeeToUpdate, e => e.Id == 1) as DbCompileResult;
// "UPDATE dbo.employee SET [name] = @P0 WHERE ([Id] = @P1)"
var result = builder.Delete (e => e.Id == 1) as DbCompileResult;
// "DELETE FROM Employee WHERE ([Id] = @P0)"
var employee = new Employee() { Id = 1, Name = "Employee Name" };
var result = builder.Insert(employee) as DbCompileResult;
// "INSERT INTO Employee ([Id],[Name]) VALUES (@P0,@P1)"