public void Select_SingleOrDefault_Adhoc_WithParameters_NonEntity_OrderShippingDate() { DateTime orderShippingDate; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); orderShippingDate = Database.Connect(connection).Prepared() .WithParameters(new { OrderID = 505L }) .Select(@"select o.ShippingDate from Orders o where o.ID = @OrderID") .SingleOrDefault <DateTime>(); orderShippingDate = Database.Connect(connection).Prepared() .WithParameters(new { OrderID = 505L }) .Select(@"select o.ShippingDate from Orders o where o.ID = @OrderID") .SingleOrDefault <DateTime>(); connection.Close(); } }
public void Select_WithCallBack_Refresh__With_Key_Customers() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers") .WithCallBack(e => new { e.ID, e.RV, e.LastName, e.FirstName }) .Refresh(context.Customers); connection.Close(); } context.Customers[0].NationalIdentityNumber = "9999999999"; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers") .WithCallBack(e => new { e.ID, e.NationalIdentityNumber }) .Refresh(context.Customers); connection.Close(); } }
private void Truncate_And_Insert() { EntityDatabaseConnection connection = GetConnection(); connection.Open(); Database.Connect(connection) .Prepared() .WithParameters(new { ID = long.MaxValue, PostalCode = "1234554321", Telephone = "99911223344", Cellphone = "09991112233" }) .Query(@"set nocount on; truncate table Shipments; set identity_insert Shipments on; insert into Shipments(ID, PostalCode, Telephone, Cellphone) values (@ID, @PostalCode, @Telephone, @Cellphone); set identity_insert Shipments off; ") .Execute(); connection.Close(); }
public void Select_FirstOrDefaultAsync_Prepared_WithParameters_NonEntity_Customers() { NonEntity.Customer customer; EntityDatabaseConnection connection = GetConnection(); connection.Open(); var t = Database.Connect(connection).Prepared() .WithParameters(new { CustomerID = 16 }) .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c where c.ID = @CustomerID waitfor delay '00:00:01'") .FirstOrDefaultAsync <NonEntity.Customer>() .ContinueWith(task => { customer = task.Result; connection.Close(); }); // do some work here, then wait for select command to be returned ... t.Wait(); }
public void Select_SingleAsync_Prepared_WithParameters_NonEntity_CustomerFirstPartnerID() { int?customerFirstPartnerID; EntityDatabaseConnection connection = GetConnection(); connection.Open(); var t = Database.Connect(connection).Prepared() .WithParameters(new { CustomerID = 16 }) .Select(@"select c.FirstPartnerID from Customers c where c.ID = @CustomerID waitfor delay '00:00:01'") .SingleAsync <int?>() .ContinueWith(task => { customerFirstPartnerID = task.Result; connection.Close(); }); // do some work here, then wait for select command to be returned ... t.Wait(); }
public void SaveBatch_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.ExecuteBatch((context, connection).WithCheckConcurrency().Save); } Overflow(Save); }
public void Save_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Execute((context, connection).WithCheckConcurrency().Save); } Hierarchical(Save); }
public void SaveBatch_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.ExecuteBatch((context, connection).WithoutCallBack().Save); } Hierarchical(Save); }
public void Save_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Execute((context, connection).WithoutCallBack().Save); } Overflow(Save); }
public void Save_Conflict_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); (context, connection).WithoutCallBack().Save(false); } Conflict(Save); }
public void Save_Conflict_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); (context, connection).WithCheckConcurrency().Save(false); } Conflict(Save); }
public void Save_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Execute((context, connection).WithoutCallBack().Save); } ConflictOnUpdate(Save); ConflictOnDelete(Save); }
public void SaveBatch_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.ExecuteBatch((context, connection).WithoutCallBack().Save); } ConcurrencyOnUpdate(Save, false, false); ConcurrencyOnDelete(Save, true, false); }
public void Save_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Execute((context, connection).WithCheckConcurrency().Save); } ConcurrencyOnUpdate(Save, true, false); ConcurrencyOnDelete(Save, true, false); }
public void SaveBatch_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.ExecuteBatch((context, connection).WithCheckConcurrency().Save); } ConflictOnUpdate(Save); ConflictOnDelete(Save); }
public void Select_ToArray_Prepared_WithoutParameters_NonEntity_Anonymous_Customers() { using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); var customers = Database.Connect(connection).Prepared() .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c") .ToArray(() => new { ID = default(int), RV = default(Types.RowVersion), FName = default(string), LName = default(string), NIN = default(string) }); connection.Close(); } }
public void Select_WithoutCallBack_Fill_Customers() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers") .Fill(context.Customers); connection.Close(); } }
public void Select_FirstOrDefault_Adhoc_WithoutParameters_NonEntity_Customers() { NonEntity.Customer customer; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); customer = Database.Connect(connection).Adhoc() .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c") .FirstOrDefault <NonEntity.Customer>(); connection.Close(); } }
public void Select_ToArray_Prepared_WithoutParameters_NonEntity_Customers() { NonEntity.Customer[] customers; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); customers = Database.Connect(connection).Prepared() .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c") .ToArray <NonEntity.Customer>(); connection.Close(); } }
public void Select_FirstOrDefault_Adhoc_WithParameters_NonEntity_Anonymous_Customers() { using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); var customer = Database.Connect(connection).Adhoc() .WithParameters(new { CustomerID = 16 }) .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c where c.ID = @CustomerID") .FirstOrDefault(() => new { ID = default(int), RV = default(Types.RowVersion), FName = default(string), LName = default(string), NIN = default(string) }); connection.Close(); } }
public void Select_WithCallBack_Products() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Product>() .Select("select * from Products") .WithCallBack(e => new { e.ID, e.Name, e.Manufacturer, e.Length, e.Width, e.Height, e.Weight, e.Color, e.Power, e.EnergyEfficiency, e.Material, e.Quality, e.Kind, e.Image, e.RV }) .Fill(context.Products); connection.Close(); } }
public void Select_WithCallBack_Merge_Without_Key_Customers() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers") .WithCallBack(e => new { e.RV, e.LastName, e.FirstName }) .Merge(context.Customers); connection.Close(); } }
public void Save_WithCheckConcurrency() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Open(); connection.BeginTransaction(IsolationLevel.Snapshot); (context, connection).WithCheckConcurrency().Save(false); connection.CommitTransaction(); connection.Close(); } Challenge(Save); }
public void Select_WithCallBack_Orders() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Order>() .Select("select * from Orders") .WithCallBack(e => new { e.ID, e.CustomerID, e.ReceiveDate, e.ShippingDate, e.RV }) .Fill(context.Orders); connection.Close(); } }
public void SaveBatch_WithoutCallBack() { void Save(EnterpriseContext context) { EntityDatabaseConnection connection = GetConnection(); connection.Open(); connection.BeginTransaction(IsolationLevel.Snapshot); (context, connection).WithoutCallBack().Save(); connection.CommitTransaction(); connection.Close(); } Challenge(Save); }
public void Select_WithCallBack_OrderDetails() { EnterpriseContext context = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <OrderDetail>() .Select("select * from OrderDetails") .WithCallBack(e => new { e.ID, e.RV, e.Amount, e.Fee, e.OrderID }) // OrderID is not null column, therefore it cann't be omitted in query, and must be loaded in model .Fill(context.OrderDetails); connection.Close(); } }
public void Select_WithCallBack_Fill_Customers_FiveTime() { EnterpriseContext context1 = new EnterpriseContext(); EnterpriseContext context2 = new EnterpriseContext(); EnterpriseContext context3 = new EnterpriseContext(); EnterpriseContext context4 = new EnterpriseContext(); EnterpriseContext context5 = new EnterpriseContext(); using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select * from Customers") .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.NationalIdentityNumber, e.RV }) // Same As context4 .Fill(context1.Customers); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select * from Customers") .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.RV }) // Same As context5 .Fill(context2.Customers); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select * from Customers") .WithCallBack(e => new { e.ID, e.RV, e.FirstName, e.LastName, e.NationalIdentityNumber }) .Fill(context3.Customers); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select * from Customers") .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.NationalIdentityNumber, e.RV }) // Same As context1 .Fill(context4.Customers); EntityDatabase <EnterpriseContext> .Connect(connection) .Table <Customer>() .Select("select * from Customers") .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.RV }) // Same As context2 .Fill(context5.Customers); connection.Close(); } }
public void SelectAsync_Prepared_With_Transaction_With_Parameter_With_CallBack() { EnterpriseContext context = new EnterpriseContext(); var consideredCustomers = UserDefinedTableTypeCreator.Create("BigIntIDs", () => new { ID = default(long) }) .Add(new { ID = 15L }) .Add(new { ID = 19L }); EntityDatabaseConnection connection = GetConnection(); var t = EntityDatabase <EnterpriseContext> .Connect(connection) .Transaction(IsolationLevel.Snapshot) .Select(@"select * from Customers c inner join @ConsideredCustomers cc on cc.ID = c.ID declare @Orders table (ID bigint, CustomerID int, ShippingDate date, RV binary(8)) insert into @Orders select o.ID, o.CustomerID, o.ShippingDate, o.RV from Orders o inner join @ConsideredCustomers cc on cc.ID = o.CustomerID where o.ReceiveDate > parse('1398/02/01' as date using 'fa-IR') select * from @Orders o order by o.ShippingDate select * from OrderDetails od inner join @Orders o on o.ID = od.OrderID select * from Products where ID = @ProductID") .WithParameters(new { ProductID = 6005, ConsideredCustomers = consideredCustomers }) .To(context) .Fill <Customer>(e => new { e.LastName, e.NationalIdentityNumber, e.FirstName, e.ID }) .Fill <Order>(e => new { e.ShippingDate, e.RV, e.ID }) .Fill <OrderDetail>(e => new { e.Amount, e.RV, e.Fee, e.ID, e.OrderID }) // OrderID is not null column, therefore it cann't be omitted in query, and must be loaded in model .Fill <Product>(e => new { e.ID, e.Name, e.Manufacturer }) .ExecuteAsync(); t.Wait(); }
public void Select_ToArray_Adhoc_WithParameters_NonEntity_Customers() { NonEntity.Customer[] customers; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); customers = Database.Connect(connection).Adhoc() .WithParameters(new { CustomerID = 16 }) .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn from Customers c where c.ID = @CustomerID") .ToArray <NonEntity.Customer>(); connection.Close(); } }
public void Select_SingleOrDefault_Adhoc_WithParameters_NonEntity_ProductImage() { byte[] productImage; using (EntityDatabaseConnection connection = GetConnection()) { connection.Open(); productImage = Database.Connect(connection).Prepared() .WithParameters(new { ProductID = 6005 }) .Select(@"select p.Image from Products p where p.ID = @ProductID") .SingleOrDefault <byte[]>(); connection.Close(); } }