diff --git a/DynamORM.Tests/Helpers/AttachToDebugger.cs.bak b/DynamORM.Tests/Helpers/AttachToDebugger.cs.bak deleted file mode 100644 index d3eec73..0000000 --- a/DynamORM.Tests/Helpers/AttachToDebugger.cs.bak +++ /dev/null @@ -1,57 +0,0 @@ -/* - * DynamORM - Dynamic Object-Relational Mapping library. - * Copyright (c) 2012, Grzegorz Russek (grzegorz.russek@gmail.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. -*/ - -using System.Diagnostics; -using NUnit.Framework; - -namespace DynamORM.Tests.Helpers -{ - /// Class responsible for users operations testing. - [TestFixture] - public class AttachToDebugger - { - /// Attach to debugger. - [Test] - [Explicit("Test for attaching debugger to NUnit test framework")] - public void Attach() - { - if (!Debugger.IsAttached) - Debugger.Launch(); - } - - /// Test anonymous type compatybility. - [Test] - public void TestAnonType () - { - var a = new { x = 1, y = 2 }; - var b = new { x = 3, y = 4 }; - - Assert.AreEqual (a.GetType (), b.GetType ()); - } - } -} \ No newline at end of file diff --git a/DynamORM/DynamicCommand.cs b/DynamORM/DynamicCommand.cs index 674d823..da4b605 100644 --- a/DynamORM/DynamicCommand.cs +++ b/DynamORM/DynamicCommand.cs @@ -38,7 +38,7 @@ namespace DynamORM private int? _commandTimeout = null; private DynamicConnection _con; private DynamicDatabase _db; - private long _poolStamp = 0; + ////private long _poolStamp = 0; /// Initializes a new instance of the class. /// The connection. @@ -74,7 +74,7 @@ namespace DynamORM internal IDbCommand PrepareForExecution() { // TODO: Fix that - // if (_poolStamp < _db.PoolStamp) + ////if (_poolStamp < _db.PoolStamp) { _command.CommandTimeout = _commandTimeout ?? _db.CommandTimeout ?? _command.CommandTimeout; @@ -83,7 +83,7 @@ namespace DynamORM else _command.Transaction = null; - _poolStamp = _db.PoolStamp; + ////_poolStamp = _db.PoolStamp; } return _db.DumpCommands ? _command.Dump(Console.Out) : _command; @@ -128,7 +128,7 @@ namespace DynamORM if (_con != null) { - _poolStamp = 0; + ////_poolStamp = 0; _command.Connection = _con.Connection; } else diff --git a/DynamORM/DynamicExtensions.cs b/DynamORM/DynamicExtensions.cs index 93a88e0..532ddfa 100644 --- a/DynamORM/DynamicExtensions.cs +++ b/DynamORM/DynamicExtensions.cs @@ -1007,6 +1007,23 @@ namespace DynamORM return mapper.Create(item); } + /// Converts the elements of an + /// to the specified type. + /// The type to convert the elements of source to. + /// The that + /// contains the elements to be converted. + /// An enumerator that contains each element of + /// the source sequence converted to the specified type. + /// Thrown when + /// source is null. + /// An element in the + /// sequence cannot be cast to type T or enumerator + /// is not . + public static IEnumerable CastEnumerable(this object enumerator) + { + return (enumerator as System.Collections.IEnumerable).Cast(); + } + #endregion Mapper extensions #region TryParse extensions diff --git a/DynamORM/DynamicTable.cs b/DynamORM/DynamicTable.cs index cf7a010..08050df 100644 --- a/DynamORM/DynamicTable.cs +++ b/DynamORM/DynamicTable.cs @@ -59,6 +59,136 @@ namespace DynamORM /// cast, because Query also returns dynamic object enumerator. /// (db.Table<User>().Query().Execute() as IEnumerable<object>).MapEnumerable<User>(); /// + /// Below you can find various invocations of dynamic and non dynemic + /// methods of this class. x variable is a class instance. + /// First various selects: + /// x.Count(columns: "id"); + /// x.Count(last: new DynamicColumn + /// { + /// Operator = DynamicColumn.CompareOperator.In, + /// Value = new object[] { "Hendricks", "Goodwin", "Freeman" }.Take(3) + /// }); + /// x.Count(last: new DynamicColumn + /// { + /// Operator = DynamicColumn.CompareOperator.In, + /// Value = new object[] { "Hendricks", "Goodwin", "Freeman" } + /// }); + /// x.First(columns: "id").id; + /// x.Last(columns: "id").id; + /// x.Count(first: "Ori"); + /// x.Min(columns: "id"); + /// x.Max(columns: "id"); + /// x.Avg(columns: "id"); + /// x.Sum(columns: "id"); + /// x.Scalar(columns: "first", id: 19); + /// x.Scalar(columns: "first:first:group_concat", id: new DynamicColumn { Operator = DynamicColumn.CompareOperator.Lt, Value = 20 }); + /// x.Scalar(columns: "group_concat(first):first", id: new DynamicColumn { Operator = DynamicColumn.CompareOperator.Lt, Value = 20 }); + /// var v = (x.Query(columns: "first,first:occurs:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList(); + /// x.Scalar(columns: @"length(""login""):len:avg"); + /// x.Avg(columns: @"length(""email""):len"); + /// x.Count(condition1: + /// new DynamicColumn() + /// { + /// ColumnName = "email", + /// Aggregate = "length", + /// Operator = DynamicColumn.CompareOperator.Gt, + /// Value = 27 + /// }); + /// var o = x.Single(columns: "id,first,last", id: 19); + /// x.Single(where: new DynamicColumn("id").Eq(100)).login; + /// x.Count(where: new DynamicColumn("id").Not(100)); + /// x.Single(where: new DynamicColumn("login").Like("Hoyt.%")).id; + /// x.Count(where: new DynamicColumn("login").NotLike("Hoyt.%")); + /// x.Count(where: new DynamicColumn("id").Greater(100)); + /// x.Count(where: new DynamicColumn("id").GreaterOrEqual(100)); + /// x.Count(where: new DynamicColumn("id").Less(100)); + /// x.Count(where: new DynamicColumn("id").LessOrEqual(100)); + /// x.Count(where: new DynamicColumn("id").Between(75, 100)); + /// x.Count(where: new DynamicColumn("id").In(75, 99, 100)); + /// x.Count(where: new DynamicColumn("id").In(new[] { 75, 99, 100 })); + /// Inserts: + /// x.Insert(code: 201, first: "Juri", last: "Gagarin", email: "juri.gagarin@megacorp.com", quote: "bla, bla, bla"); + /// x.Insert(values: new { code = 202, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" }); + /// x.Insert(values: new Users + /// { + /// Id = u.Max(columns: "id") + 1, + /// Code = "203", + /// First = "Juri", + /// Last = "Gagarin", + /// Email = "juri.gagarin@megacorp.com", + /// Quote = "bla, bla, bla" + /// }); + /// x.Insert(values: new users + /// { + /// id = u.Max(columns: "id") + 1, + /// code = "204", + /// first = "Juri", + /// last = "Gagarin", + /// email = "juri.gagarin@megacorp.com", + /// quote = "bla, bla, bla" + /// }); + /// x.Update(id: 1, code: 201, first: "Juri", last: "Gagarin", email: "juri.gagarin@megacorp.com", quote: "bla, bla, bla"); + /// x.Update(update: new { id = 2, code = 202, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" }); + /// Updates: + /// x.Update(update: new Users + /// { + /// Id = 3, + /// Code = "203", + /// First = "Juri", + /// Last = "Gagarin", + /// Email = "juri.gagarin@megacorp.com", + /// Quote = "bla, bla, bla" + /// }); + /// x.Update(update: new users + /// { + /// id = 4, + /// code = "204", + /// first = "Juri", + /// last = "Gagarin", + /// email = "juri.gagarin@megacorp.com", + /// quote = "bla, bla, bla" + /// }); + /// x.Update(values: new { code = 205, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" }, where: new { id = 5 }); + /// x.Update(values: new Users + /// { + /// Id = 6, + /// Code = "206", + /// First = "Juri", + /// Last = "Gagarin", + /// Email = "juri.gagarin@megacorp.com", + /// Quote = "bla, bla, bla" + /// }, id: 6); + /// x.Update(values: new users + /// { + /// id = 7, + /// code = "207", + /// first = "Juri", + /// last = "Gagarin", + /// email = "juri.gagarin@megacorp.com", + /// quote = "bla, bla, bla" + /// }, id: 7); + /// Delete: + /// x.Delete(code: 10); + /// x.Delete(delete: new { id = 11, code = 11, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" }); + /// x.Delete(delete: new Users + /// { + /// Id = 12, + /// Code = "12", + /// First = "Juri", + /// Last = "Gagarin", + /// Email = "juri.gagarin@megacorp.com", + /// Quote = "bla, bla, bla" + /// }); + /// x.Delete(delete: new users + /// { + /// id = 13, + /// code = "13", + /// first = "Juri", + /// last = "Gagarin", + /// email = "juri.gagarin@megacorp.com", + /// quote = "bla, bla, bla" + /// }); + /// x.Delete(where: new { id = 14, code = 14 }); /// public class DynamicTable : DynamicObject, IDisposable, ICloneable {