This commit is contained in:
@@ -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
|
||||
{
|
||||
/// <summary>Class responsible for users operations testing.</summary>
|
||||
[TestFixture]
|
||||
public class AttachToDebugger
|
||||
{
|
||||
/// <summary>Attach to debugger.</summary>
|
||||
[Test]
|
||||
[Explicit("Test for attaching debugger to NUnit test framework")]
|
||||
public void Attach()
|
||||
{
|
||||
if (!Debugger.IsAttached)
|
||||
Debugger.Launch();
|
||||
}
|
||||
|
||||
/// <summary>Test anonymous type compatybility.</summary>
|
||||
[Test]
|
||||
public void TestAnonType ()
|
||||
{
|
||||
var a = new { x = 1, y = 2 };
|
||||
var b = new { x = 3, y = 4 };
|
||||
|
||||
Assert.AreEqual (a.GetType (), b.GetType ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace DynamORM
|
||||
private int? _commandTimeout = null;
|
||||
private DynamicConnection _con;
|
||||
private DynamicDatabase _db;
|
||||
private long _poolStamp = 0;
|
||||
////private long _poolStamp = 0;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="DynamicCommand"/> class.</summary>
|
||||
/// <param name="con">The connection.</param>
|
||||
@@ -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
|
||||
|
||||
@@ -1007,6 +1007,23 @@ namespace DynamORM
|
||||
return mapper.Create(item);
|
||||
}
|
||||
|
||||
/// <summary>Converts the elements of an <see cref="System.Collections.IEnumerable"/>
|
||||
/// to the specified type.</summary>
|
||||
/// <typeparam name="T">The type to convert the elements of source to.</typeparam>
|
||||
/// <param name="enumerator">The <see cref="System.Collections.IEnumerable"/> that
|
||||
/// contains the elements to be converted.</param>
|
||||
/// <returns>An enumerator that contains each element of
|
||||
/// the source sequence converted to the specified type.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown when
|
||||
/// <c>source</c> is null.</exception>
|
||||
/// <exception cref="System.InvalidCastException">An element in the
|
||||
/// sequence cannot be cast to type <c>T</c> or <c>enumerator</c>
|
||||
/// is not <see cref="System.Collections.IEnumerable"/>.</exception>
|
||||
public static IEnumerable<T> CastEnumerable<T>(this object enumerator)
|
||||
{
|
||||
return (enumerator as System.Collections.IEnumerable).Cast<T>();
|
||||
}
|
||||
|
||||
#endregion Mapper extensions
|
||||
|
||||
#region TryParse extensions
|
||||
|
||||
@@ -59,6 +59,136 @@ namespace DynamORM
|
||||
/// cast, because <c>Query</c> also returns dynamic object enumerator.</para>
|
||||
/// <code>(db.Table<User>().Query().Execute() as IEnumerable<object>).MapEnumerable<User>();</code>
|
||||
/// </para>
|
||||
/// <para>Below you can find various invocations of dynamic and non dynemic
|
||||
/// methods of this class. <c>x</c> variable is a class instance.
|
||||
/// First various selects:</para>
|
||||
/// <code>x.Count(columns: "id");</code>
|
||||
/// <code>x.Count(last: new DynamicColumn
|
||||
/// {
|
||||
/// Operator = DynamicColumn.CompareOperator.In,
|
||||
/// Value = new object[] { "Hendricks", "Goodwin", "Freeman" }.Take(3)
|
||||
/// });</code>
|
||||
/// <code>x.Count(last: new DynamicColumn
|
||||
/// {
|
||||
/// Operator = DynamicColumn.CompareOperator.In,
|
||||
/// Value = new object[] { "Hendricks", "Goodwin", "Freeman" }
|
||||
/// });</code>
|
||||
/// <code>x.First(columns: "id").id;</code>
|
||||
/// <code>x.Last(columns: "id").id;</code>
|
||||
/// <code>x.Count(first: "Ori");</code>
|
||||
/// <code>x.Min(columns: "id");</code>
|
||||
/// <code>x.Max(columns: "id");</code>
|
||||
/// <code>x.Avg(columns: "id");</code>
|
||||
/// <code>x.Sum(columns: "id");</code>
|
||||
/// <code>x.Scalar(columns: "first", id: 19);</code>
|
||||
/// <code>x.Scalar(columns: "first:first:group_concat", id: new DynamicColumn { Operator = DynamicColumn.CompareOperator.Lt, Value = 20 });</code>
|
||||
/// <code>x.Scalar(columns: "group_concat(first):first", id: new DynamicColumn { Operator = DynamicColumn.CompareOperator.Lt, Value = 20 });</code>
|
||||
/// <code>var v = (x.Query(columns: "first,first:occurs:count", group: "first", order: ":desc:2") as IEnumerable<dynamic>).ToList();</code>
|
||||
/// <code>x.Scalar(columns: @"length(""login""):len:avg");</code>
|
||||
/// <code>x.Avg(columns: @"length(""email""):len");</code>
|
||||
/// <code>x.Count(condition1:
|
||||
/// new DynamicColumn()
|
||||
/// {
|
||||
/// ColumnName = "email",
|
||||
/// Aggregate = "length",
|
||||
/// Operator = DynamicColumn.CompareOperator.Gt,
|
||||
/// Value = 27
|
||||
/// });</code>
|
||||
/// <code>var o = x.Single(columns: "id,first,last", id: 19);</code>
|
||||
/// <code>x.Single(where: new DynamicColumn("id").Eq(100)).login;</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").Not(100));</code>
|
||||
/// <code>x.Single(where: new DynamicColumn("login").Like("Hoyt.%")).id;</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("login").NotLike("Hoyt.%"));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").Greater(100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").GreaterOrEqual(100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").Less(100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").LessOrEqual(100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").Between(75, 100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").In(75, 99, 100));</code>
|
||||
/// <code>x.Count(where: new DynamicColumn("id").In(new[] { 75, 99, 100 }));</code>
|
||||
/// Inserts:
|
||||
/// <code>x.Insert(code: 201, first: "Juri", last: "Gagarin", email: "juri.gagarin@megacorp.com", quote: "bla, bla, bla");</code>
|
||||
/// <code>x.Insert(values: new { code = 202, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" });</code>
|
||||
/// <code>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"
|
||||
/// });</code>
|
||||
/// <code>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"
|
||||
/// });</code>
|
||||
/// <code>x.Update(id: 1, code: 201, first: "Juri", last: "Gagarin", email: "juri.gagarin@megacorp.com", quote: "bla, bla, bla");</code>
|
||||
/// <code>x.Update(update: new { id = 2, code = 202, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" });</code>
|
||||
/// Updates:
|
||||
/// <code>x.Update(update: new Users
|
||||
/// {
|
||||
/// Id = 3,
|
||||
/// Code = "203",
|
||||
/// First = "Juri",
|
||||
/// Last = "Gagarin",
|
||||
/// Email = "juri.gagarin@megacorp.com",
|
||||
/// Quote = "bla, bla, bla"
|
||||
/// });</code>
|
||||
/// <code>x.Update(update: new users
|
||||
/// {
|
||||
/// id = 4,
|
||||
/// code = "204",
|
||||
/// first = "Juri",
|
||||
/// last = "Gagarin",
|
||||
/// email = "juri.gagarin@megacorp.com",
|
||||
/// quote = "bla, bla, bla"
|
||||
/// });</code>
|
||||
/// <code>x.Update(values: new { code = 205, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" }, where: new { id = 5 });</code>
|
||||
/// <code>x.Update(values: new Users
|
||||
/// {
|
||||
/// Id = 6,
|
||||
/// Code = "206",
|
||||
/// First = "Juri",
|
||||
/// Last = "Gagarin",
|
||||
/// Email = "juri.gagarin@megacorp.com",
|
||||
/// Quote = "bla, bla, bla"
|
||||
/// }, id: 6);</code>
|
||||
/// <code>x.Update(values: new users
|
||||
/// {
|
||||
/// id = 7,
|
||||
/// code = "207",
|
||||
/// first = "Juri",
|
||||
/// last = "Gagarin",
|
||||
/// email = "juri.gagarin@megacorp.com",
|
||||
/// quote = "bla, bla, bla"
|
||||
/// }, id: 7);</code>
|
||||
/// Delete:
|
||||
/// <code>x.Delete(code: 10);</code>
|
||||
/// <code>x.Delete(delete: new { id = 11, code = 11, first = "Juri", last = "Gagarin", email = "juri.gagarin@megacorp.com", quote = "bla, bla, bla" });</code>
|
||||
/// <code>x.Delete(delete: new Users
|
||||
/// {
|
||||
/// Id = 12,
|
||||
/// Code = "12",
|
||||
/// First = "Juri",
|
||||
/// Last = "Gagarin",
|
||||
/// Email = "juri.gagarin@megacorp.com",
|
||||
/// Quote = "bla, bla, bla"
|
||||
/// });</code>
|
||||
/// <code>x.Delete(delete: new users
|
||||
/// {
|
||||
/// id = 13,
|
||||
/// code = "13",
|
||||
/// first = "Juri",
|
||||
/// last = "Gagarin",
|
||||
/// email = "juri.gagarin@megacorp.com",
|
||||
/// quote = "bla, bla, bla"
|
||||
/// });</code>
|
||||
/// <code>x.Delete(where: new { id = 14, code = 14 });</code>
|
||||
/// </example>
|
||||
public class DynamicTable : DynamicObject, IDisposable, ICloneable
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user