Skip to content

This is a tiny library with which you can extend the possibilities of the OracleClient. Easy way to get Entities, ExpandoObjects and much more.

License

Notifications You must be signed in to change notification settings

dvXcode/OracleClientExtension

Repository files navigation

Latest nuget release

OracleClientExtension

This is a tiny library with which you can extend the possibilities of the OracleClient. Easy way to get Entities, ExpandoObjects and much more.

Features

  • Retrive data as ExpandoObject
  • Retrive data as Entity T
  • Test

Installing

Via Package Manager

Install-Package OracleClientExtension -Version 0.2.5

Via .NET CLI

dotnet add package OracleClientExtension --version 0.2.5

Samples

Get data from table as ExpandoObjects

private readonly string _connectionString = "Data Source=localhost/XE;Persist Security Info=True;User ID=USER;Password=PASSWORD";
...
try
{
    await using var conn = new OracleConnection(connectionString: _connectionString);
    await conn.OpenAsync();
    var resp = await conn.ExecuteExpandoObjectsAsync("SELECT * FROM DEMO WHERE ROWNUM <= 10");
}
catch (Exception ex)
{
    throw ex;
}

Get data from table as custom Entity object

private readonly string _connectionString = "Data Source=localhost/XE;Persist Security Info=True;User ID=USER;Password=PASSWORD";
...
public class DemoEntity
{
	public int EMPNO { get; set; }
	public string ENAME { get; set; }
	public string JOB { get; set; }
	public DateTime HIREDATE { get; set; }
	public int DEPTNO { get; set; }
}
...
try
{
    await using var conn = new OracleConnection(connectionString: _connectionString);
    await conn.OpenAsync();
    var resp = await conn.ExecuteEntitiesAsync<DemoEntity>("SELECT * FROM DEMO WHERE ROWNUM <= 10");
}
catch (Exception ex)
{
    throw ex;
}

Get data as DataSet

private readonly string _connectionString = "Data Source=localhost/XE;Persist Security Info=True;User ID=USER;Password=PASSWORD";
...
try
{
    await using var conn = new OracleConnection(connectionString: _connectionString);
    await conn.OpenAsync();
    var resp = await conn.ExecuteDataSetAsync("SELECT * FROM DEMO WHERE ROWNUM <= 10");
}
catch (Exception ex)
{
    throw ex;
}

Get data from table as ExpandoObjects with output OracleParameter

private readonly string _connectionString = "Data Source=localhost/XE;Persist Security Info=True;User ID=USER;Password=PASSWORD";
...
try
{
    await using var conn = new OracleConnection(connectionString: _connectionString);
    await conn.OpenAsync();
    
    var param = new OracleParameter[1];
    var countParam = new OracleParameter
    {
	ParameterName = ":1",
	OracleDbType = OracleDbType.Int32,
	Direction = ParameterDirection.Output
    };

    param[0] = countParam;
    var resp = await conn.ExecuteExpandoObjectsAsync("BEGIN SELECT COUNT(*) INTO :1 FROM DEMO; END;", param);
}
catch (Exception ex)
{
    throw ex;
}

Update table with ExecuteNonQueryAsync and OracleParameters

private readonly string _connectionString = "Data Source=localhost/XE;Persist Security Info=True;User ID=USER;Password=PASSWORD";
...
try
{
    await using var conn = new OracleConnection(connectionString: _connectionString);
    await conn.OpenAsync();
    
    var command = conn.CreateCommand();
    command.Parameters.Add(new OracleParameter("ENAME", "JOHN GROSS"));
    command.Parameters.Add(new OracleParameter("HIREDATE", OracleDbType.Date, DateTime.Now, ParameterDirection.Input));
    command.CommandText = "UPDATE DEMO SET ENAME=:ENAME WHERE HIREDATE=:HIREDATE ";

    param[0] = countParam;
    int rowsUpdated = await command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
    throw ex;
}

Todo

  • Add Sample app
  • Add Tests
  • Add documentation

Pull requests are more than welcomed!

License

You can check out the full license here

This project is licensed under the terms of the MPL-2.0 license.

About

This is a tiny library with which you can extend the possibilities of the OracleClient. Easy way to get Entities, ExpandoObjects and much more.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages