This commit is contained in:
@@ -13,32 +13,40 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<NoWin32Manifest>False</NoWin32Manifest>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<DelaySign>False</DelaySign>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>False</Prefer32Bit>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DebugType>PdbOnly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>False</Prefer32Bit>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
@@ -47,13 +55,21 @@
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>False</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>C:\Program Files %28x86%29\NUnit 2.6.3\bin\framework\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>Libraries\System.Data.SQLite.dll</HintPath>
|
||||
<HintPath>..\..\..\Libs\SQLite\Any\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@@ -81,10 +97,10 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Select\LegacyParserTests.cs" />
|
||||
<Compile Include="Select\RenamedTypedAccessTests.cs" />
|
||||
<Compile Include="Select\ParserTests.cs" />
|
||||
<Compile Include="TestsBase.cs" />
|
||||
<Compile Include="Select\TypedAccessTests.cs" />
|
||||
<Compile Include="Select\RenamedTypedAccessTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DynamORM.Tests.Helpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -41,5 +42,25 @@ namespace DynamORM.Tests.Modify
|
||||
{
|
||||
return Database.Table<users>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBulkInsert()
|
||||
{
|
||||
Assert.AreEqual(2, Database.Insert<users>(new List<users>
|
||||
{
|
||||
new users
|
||||
{
|
||||
id = 1001,
|
||||
login = "a",
|
||||
},
|
||||
new users
|
||||
{
|
||||
id = 1002,
|
||||
login = "b",
|
||||
}
|
||||
}));
|
||||
|
||||
Assert.AreEqual(2, Database.Delete<users>().Where(u => u.users.id.In(1001, 1002)).Execute());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ using NUnit.Framework;
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Tests of legacy parser methods.</summary>
|
||||
[TestFixture]
|
||||
public class LegacyParserTests : TestsBase
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace DynamORM.Tests.Select
|
||||
/// <summary>
|
||||
/// New parser tests.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ParserTests : TestsBase
|
||||
{
|
||||
/// <summary>Setup test parameters.</summary>
|
||||
|
||||
@@ -34,6 +34,7 @@ using NUnit.Framework;
|
||||
namespace DynamORM.Tests.Select
|
||||
{
|
||||
/// <summary>Test typed ORM.</summary>
|
||||
[TestFixture]
|
||||
public class RenamedTypedAccessTests : TypedAccessTests<Users>
|
||||
{
|
||||
/// <summary>Test something fancy... like: <code>select "first", count("first") aggregatefield from "users" group by "first" order by 2 desc;</code>.</summary>
|
||||
|
||||
13
DynamORM.sln
13
DynamORM.sln
@@ -1,12 +1,11 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
# SharpDevelop 4.2.2.8818
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamORM", "DynamORM\DynamORM.csproj", "{63963ED7-9C78-4672-A4D4-339B6E825503}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamORM.Tests", "DynamORM.Tests\DynamORM.Tests.csproj", "{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Workbench", "Workbench\Workbench.csproj", "{01429808-B1A9-4272-852E-B2F7649BD788}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -37,16 +36,6 @@ Global
|
||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Debug|x86.Build.0 = Debug|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Release|x86.ActiveCfg = Release|x86
|
||||
{01429808-B1A9-4272-852E-B2F7649BD788}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -53,22 +53,6 @@ namespace DynamORM.Builders
|
||||
/// <returns>Result of a query.</returns>
|
||||
object Scalar();
|
||||
|
||||
#region SubQuery
|
||||
|
||||
/// <summary>Adds to the 'From' clause of sub query the contents obtained by
|
||||
/// parsing the dynamic lambda expressions given. The supported formats are:
|
||||
/// <para>- Resolve to a string: 'x => "Table AS Alias', where the alias part is optional.</para>
|
||||
/// <para>- Resolve to an expression: 'x => x.Table.As( x.Alias )', where the alias part is optional.</para>
|
||||
/// <para>- Generic expression: 'x => x( expression ).As( x.Alias )', where the alias part is mandatory. In this
|
||||
/// case the alias is not annotated.</para>
|
||||
/// </summary>
|
||||
/// <param name="subquery">First argument is parent query, second one is a subquery.</param>
|
||||
/// <param name="func">The specification for subquery.</param>
|
||||
/// <returns>This instance to permit chaining.</returns>
|
||||
IDynamicSelectQueryBuilder SubQuery(Action<IDynamicSelectQueryBuilder, IDynamicSelectQueryBuilder> subquery, params Func<dynamic, object>[] func);
|
||||
|
||||
#endregion SubQuery
|
||||
|
||||
#region From/Join
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -360,7 +360,7 @@ namespace DynamORM.Builders.Implementation
|
||||
return ParseConstant(node, pars, columnSchema);
|
||||
}
|
||||
|
||||
protected virtual string ParseCommand(DynamicQueryBuilder node, IDictionary<string, IParameter> pars = null)
|
||||
internal virtual string ParseCommand(DynamicQueryBuilder node, IDictionary<string, IParameter> pars = null)
|
||||
{
|
||||
// Getting the command's text...
|
||||
string str = node.CommandText(); // Avoiding spurious "OUTPUT XXX" statements
|
||||
|
||||
@@ -241,34 +241,6 @@ namespace DynamORM.Builders.Implementation
|
||||
|
||||
#endregion Execution
|
||||
|
||||
#region Subquery
|
||||
|
||||
/// <summary>
|
||||
/// Adds to the 'From' clause of sub query the contents obtained by
|
||||
/// parsing the dynamic lambda expressions given. The supported formats are:
|
||||
/// <para>- Resolve to a string: 'x => "Table AS Alias', where the alias part is optional.</para>
|
||||
/// <para>- Resolve to an expression: 'x => x.Table.As( x.Alias )', where the alias part is optional.</para>
|
||||
/// <para>- Generic expression: 'x => x( expression ).As( x.Alias )', where the alias part is mandatory. In this
|
||||
/// case the alias is not annotated.</para>
|
||||
/// </summary>
|
||||
/// <param name="subquery">First argument is parent query, second one is a subquery.</param>
|
||||
/// <param name="func">The specification for subquery.</param>
|
||||
/// <returns>
|
||||
/// This instance to permit chaining.
|
||||
/// </returns>
|
||||
public virtual IDynamicSelectQueryBuilder SubQuery(Action<IDynamicSelectQueryBuilder, IDynamicSelectQueryBuilder> subquery, params Func<dynamic, object>[] func)
|
||||
{
|
||||
var sub = func == null || func.Length == 0 ? base.SubQuery() : base.SubQuery(func);
|
||||
|
||||
subquery(this, sub);
|
||||
|
||||
ParseCommand(sub as DynamicQueryBuilder, Parameters);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion Subquery
|
||||
|
||||
#region From/Join
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<DelaySign>False</DelaySign>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -26,17 +31,23 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DebugType>PdbOnly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<DocumentationFile>bin\Release\DynamORM.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
|
||||
@@ -286,6 +286,61 @@ namespace DynamORM
|
||||
{
|
||||
return new DynamicInsertQueryBuilder(this).Table(typeof(T));
|
||||
}
|
||||
|
||||
public virtual int Insert<T>(IEnumerable<T> e) where T : class
|
||||
{
|
||||
int affected = 0;
|
||||
var mapper = DynamicMapperCache.GetMapper(typeof(T));
|
||||
|
||||
if (mapper != null)
|
||||
using (var con = Open())
|
||||
using (var tra = con.BeginTransaction())
|
||||
using (var cmd = con.CreateCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
DynamicPropertyInvoker currentprop = null;
|
||||
var temp = new Dictionary<string, DynamicPropertyInvoker>();
|
||||
var parameters = new Dictionary<IDbDataParameter, DynamicPropertyInvoker>();
|
||||
|
||||
var ib = Insert<T>()
|
||||
.SetVirtualMode(true)
|
||||
.CreateTemporaryParameterAction(p => temp[p.Name] = currentprop)
|
||||
.CreateParameterAction((p, cp) => parameters[cp] = temp[p.Name]);
|
||||
|
||||
foreach (var prop in mapper.PropertyMap)
|
||||
if (!mapper.Ignored.Contains(prop.Key))
|
||||
{
|
||||
var col = mapper.PropertyMap.TryGetValue(prop.Key) ?? prop.Key;
|
||||
currentprop = mapper.ColumnsMap.TryGetValue(col.ToLower());
|
||||
|
||||
if (currentprop.Get != null)
|
||||
ib.Insert(col, null);
|
||||
}
|
||||
|
||||
ib.FillCommand(cmd);
|
||||
|
||||
foreach (var o in e)
|
||||
{
|
||||
foreach (var m in parameters)
|
||||
m.Key.Value = m.Value.Get(o);
|
||||
|
||||
affected += cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
tra.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (tra != null)
|
||||
tra.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds to the <code>UPDATE</code> clause the contents obtained by parsing the dynamic lambda expressions given. The supported
|
||||
|
||||
@@ -816,17 +816,6 @@ namespace DynamORM
|
||||
return b;
|
||||
}
|
||||
|
||||
/// <summary>Sets the virtual mode on builder.</summary>
|
||||
/// <typeparam name="T">Class implementing <see cref="IDynamicQueryBuilder"/> interface.</typeparam>
|
||||
/// <param name="b">The builder on which set delegate.</param>
|
||||
/// <param name="virtualMode">Virtual mode.</param>
|
||||
/// <returns>Returns instance of builder on which virtual mode is set.</returns>
|
||||
public static T SetVirtualMode<T>(this T b, bool virtualMode) where T : IDynamicQueryBuilder
|
||||
{
|
||||
b.VirtualMode = virtualMode;
|
||||
return b;
|
||||
}
|
||||
|
||||
/// <summary>Sets the on create real parameter action.</summary>
|
||||
/// <typeparam name="T">Class implementing <see cref="IDynamicQueryBuilder"/> interface.</typeparam>
|
||||
/// <param name="b">The builder on which set delegate.</param>
|
||||
@@ -838,6 +827,33 @@ namespace DynamORM
|
||||
return b;
|
||||
}
|
||||
|
||||
/// <summary>Sets the virtual mode on builder.</summary>
|
||||
/// <typeparam name="T">Class implementing <see cref="IDynamicQueryBuilder"/> interface.</typeparam>
|
||||
/// <param name="b">The builder on which set virtual mode.</param>
|
||||
/// <param name="virtualMode">Virtual mode.</param>
|
||||
/// <returns>Returns instance of builder on which virtual mode is set.</returns>
|
||||
public static T SetVirtualMode<T>(this T b, bool virtualMode) where T : IDynamicQueryBuilder
|
||||
{
|
||||
b.VirtualMode = virtualMode;
|
||||
return b;
|
||||
}
|
||||
|
||||
/// <summary>Creates sub query that can be used inside of from/join/expresions.</summary>
|
||||
/// <param name="b">The builder that will be parent of new sub query.</param>
|
||||
/// <param name="subquery">First argument is parent query, second one is a subquery.</param>
|
||||
/// <param name="func">The specification for subquery.</param>
|
||||
/// <returns>This instance to permit chaining.</returns>
|
||||
public static T SubQuery<T>(this T b, Action<T, IDynamicSelectQueryBuilder> subquery, params Func<dynamic, object>[] func) where T : IDynamicQueryBuilder
|
||||
{
|
||||
var sub = func == null || func.Length == 0 ? b.SubQuery() : b.SubQuery(func);
|
||||
|
||||
subquery(b, sub);
|
||||
|
||||
(b as DynamicQueryBuilder).ParseCommand(sub as DynamicQueryBuilder, b.Parameters);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
#endregion Dynamic builders extensions
|
||||
|
||||
#region Dynamic extensions
|
||||
|
||||
@@ -46,9 +46,11 @@ namespace DynamORM.Mapper
|
||||
public Func<object> Creator { get; private set; }
|
||||
|
||||
/// <summary>Gets map of columns to properties.</summary>
|
||||
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
|
||||
public Dictionary<string, DynamicPropertyInvoker> ColumnsMap { get; private set; }
|
||||
|
||||
/// <summary>Gets map of properties to column.</summary>
|
||||
/// <remarks>Key: Property name, Value: Column name.</remarks>
|
||||
public Dictionary<string, string> PropertyMap { get; private set; }
|
||||
|
||||
/// <summary>Gets list of ignored properties.</summary>
|
||||
@@ -73,6 +75,7 @@ namespace DynamORM.Mapper
|
||||
{
|
||||
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();
|
||||
var propertyMap = new Dictionary<string, string>();
|
||||
var ignored = new List<string>();
|
||||
|
||||
foreach (var pi in Type.GetProperties())
|
||||
{
|
||||
@@ -89,12 +92,15 @@ namespace DynamORM.Mapper
|
||||
columnMap.Add(col.ToLower(), val);
|
||||
|
||||
propertyMap.Add(pi.Name, col);
|
||||
|
||||
if (val.Ignore)
|
||||
ignored.Add(pi.Name);
|
||||
}
|
||||
|
||||
ColumnsMap = columnMap;
|
||||
PropertyMap = propertyMap;
|
||||
|
||||
Ignored = columnMap.Where(i => i.Value.Ignore).Select(i => i.Value.Name).ToList();
|
||||
Ignored = ignored; ////columnMap.Where(i => i.Value.Ignore).Select(i => i.Value.Name).ToList();
|
||||
}
|
||||
|
||||
private Func<object> CreateCreator()
|
||||
|
||||
Reference in New Issue
Block a user