149 lines
6.7 KiB
C#
149 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using DynamORM;
|
|
using DynamORM.Helpers;
|
|
|
|
namespace Tester
|
|
{
|
|
internal class Program
|
|
{
|
|
private static DynamicDatabase GetORM()
|
|
{
|
|
return new DynamicDatabase(System.Data.SqlClient.SqlClientFactory.Instance,
|
|
"packet size=4096;User Id=sa;Password=;data source=192.168.22.;initial catalog=PLAYGROUND;",
|
|
DynamicDatabaseOptions.SingleConnection | DynamicDatabaseOptions.SingleTransaction | DynamicDatabaseOptions.SupportSchema |
|
|
DynamicDatabaseOptions.SupportStoredProcedures | DynamicDatabaseOptions.SupportTop | DynamicDatabaseOptions.DumpCommands);
|
|
|
|
////return new DynamORM.DynamicDatabase(System.Data.SQLite.SQLiteFactory.Instance,
|
|
//// "Data Source=test.db3;",
|
|
//// DynamORM.DynamicDatabaseOptions.SingleConnection | DynamORM.DynamicDatabaseOptions.SingleTransaction |
|
|
//// DynamORM.DynamicDatabaseOptions.SupportSchema | DynamORM.DynamicDatabaseOptions.SupportLimitOffset);
|
|
///
|
|
}
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
//var c = new System.Data.SqlClient.SqlConnection("packet size=4096;User Id=sa;Password=sa123;data source=192.168.0.6;initial catalog=DynamORM;");
|
|
|
|
using (var db = GetORM())
|
|
{
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_Scalar AS SELECT 42;");
|
|
var res0 = db.Procedures.sp_Exp_Scalar();
|
|
var res1 = db.Procedures.sp_Exp_Scalar<int>();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_ReturnInt AS RETURN 42;");
|
|
var res2 = db.Procedures.sp_Exp_ReturnInt();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeData AS
|
|
SELECT 1 Id, 'Some Name 1' [Name], 'Some Desc 1' [Desc], GETDATE() [Date]
|
|
UNION ALL SELECT 2 Id, 'Some Name 2', 'Some Desc 2', GETDATE() [Date];");
|
|
var res3 = db.Procedures.sp_Exp_SomeData<sp_Exp_SomeData_Result>();
|
|
var res4 = db.Procedures.sp_Exp_SomeData<List<sp_Exp_SomeData_Result>>();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeInputAndOutput
|
|
@Name nvarchar(50),
|
|
@Result nvarchar(256) OUTPUT
|
|
AS
|
|
SELECT @Result = 'Hi, ' + @Name + ' your lucky number is 42!';");
|
|
var res5 = db.Procedures.sp_Exp_SomeInputAndOutput<string, sp_Exp_SomeInputAndOutput_Result>(Name: "G4g4r1n", out_Result: new DynamicColumn
|
|
{
|
|
Schema = new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
},
|
|
}, ret_Return: 0);
|
|
var res6 = db.Procedures.sp_Exp_SomeInputAndOutput<string, sp_Exp_SomeInputAndOutput_Result>(Name: "G4g4r1n", out_Result: new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
}, ret_Return: 0);
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeInputAndOutputWithDataAndReturn
|
|
@Name nvarchar(50),
|
|
@Result nvarchar(256) OUTPUT
|
|
AS
|
|
SELECT @Result = 'Hi, ' + @Name + ' your lucky number is 42!'
|
|
|
|
SELECT 1 Id, 'Some Name 1' [Name], 'Some Desc 1' [Desc], GETDATE() [Date]
|
|
UNION ALL SELECT 2 Id, 'Some Name 2', 'Some Desc 2', GETDATE() [Date]
|
|
|
|
RETURN 42;");
|
|
var res7 = db.Procedures.sp_Exp_SomeInputAndOutputWithDataAndReturn<List<sp_Exp_SomeInputAndOutputWithDataAndReturn_Result.Data>, sp_Exp_SomeInputAndOutputWithDataAndReturn_Result>(Name: "G4g4r1n", out_Result: new DynamicColumn
|
|
{
|
|
Schema = new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
},
|
|
}, ret_Return: 0);
|
|
var res8 = db.Procedures.sp_Exp_SomeInputAndOutputWithDataAndReturn<List<sp_Exp_SomeInputAndOutputWithDataAndReturn_Result.Data>, sp_Exp_SomeInputAndOutputWithDataAndReturn_Result>(Name: "G4g4r1n", out_Result: new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
}, ret_Return: 0);
|
|
|
|
//try
|
|
//{
|
|
// db.Execute("DROP TABLE Experiments ");
|
|
//}
|
|
//catch { }
|
|
|
|
//db.Execute("CREATE TABLE Experiments (t1 nvarchar(50) NOT NULL DEFAULT N'', t2 varchar(50) NOT NULL DEFAULT '');");
|
|
|
|
//var q = db.From(x => x.Experiments.As(x.e1));
|
|
//q
|
|
// .Where(x => x.t2 = "Dupa")
|
|
// .Where(x => x.Exists(
|
|
// q.SubQuery()
|
|
// .From(y => y.Experiments.As(x.e2))
|
|
// .Where(y => y.e2.t1 == y.e1.t1)))
|
|
// .Execute().ToList();
|
|
|
|
//db.Execute("DROP TABLE Experiments ");
|
|
|
|
//IDataReader rdr = db.Procedures.sp_getdate<IDataReader>();
|
|
//var dt = rdr.ToDataTable();
|
|
//var dt2 = db.Procedures.sp_getdate<DataTable>();
|
|
|
|
//db.Procedures.usp_API_Generate_Doc_Number<string>(key: Guid.NewGuid(), mdn_id: "ZZ");
|
|
|
|
//var resL = (db.Procedures.GetProductDesc<IList<GetProductDesc_Result>>() as IEnumerable<dynamic>)
|
|
// .Cast<GetProductDesc_Result>()
|
|
// .ToArray();
|
|
//var res = db.Procedures.GetProductDesc_withparameters<GetProductDesc_Result>(PID: 707);
|
|
//res = db.Procedures.GetProductDesc_withDefaultparameters<GetProductDesc_Result>();
|
|
|
|
//int id = -1;
|
|
//var resD = db.Procedures.ins_NewEmp_with_outputparamaters(Ename: "Test2", out_EId: id);
|
|
}
|
|
}
|
|
|
|
private class sp_Exp_SomeData_Result
|
|
{
|
|
public virtual int Id { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual string Desc { get; set; }
|
|
public virtual DateTime Date { get; set; }
|
|
}
|
|
|
|
private class sp_Exp_SomeInputAndOutput_Result
|
|
{
|
|
public virtual string Result { get; set; }
|
|
public virtual string Return { get; set; }
|
|
}
|
|
|
|
private class sp_Exp_SomeInputAndOutputWithDataAndReturn_Result
|
|
{
|
|
public class Data
|
|
{
|
|
public virtual int Id { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual string Desc { get; set; }
|
|
public virtual DateTime Date { get; set; }
|
|
}
|
|
|
|
public virtual List<Data> sp_Exp_SomeInputAndOutputWithDataAndReturn { get; set; }
|
|
public virtual string Result { get; set; }
|
|
public virtual string Return { get; set; }
|
|
}
|
|
}
|
|
} |