Skip to content

Commit

Permalink
Add Guid Fix
Browse files Browse the repository at this point in the history
Add Guid Fix
  • Loading branch information
zzzprojects committed Mar 3, 2018
1 parent 12c1036 commit 6bec953
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Main/Build/Effort.EF6.nuspec
Expand Up @@ -2,9 +2,9 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Effort.EF6</id>
<version>1.3.1</version>
<version>1.3.2</version>
<title />
<authors>tamasflamich, ZZZ Projects</authors>
<authors>ZZZ Projects, tamasflamich</authors>
<owners>ZZZ Projects</owners>
<iconUrl>https://zzzprojects.github.io/images/logo/logo-64.png</iconUrl>
<licenseUrl>https://github.com/zzzprojects/effort/blob/develop/LICENSE</licenseUrl>
Expand Down
4 changes: 2 additions & 2 deletions Main/Build/Effort.nuspec
Expand Up @@ -2,9 +2,9 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Effort</id>
<version>1.3.1</version>
<version>1.3.2</version>
<title />
<authors>tamasflamich, ZZZ Projects</authors>
<authors>ZZZ Projects, tamasflamich</authors>
<owners>ZZZ Projects</owners>
<iconUrl>https://zzzprojects.github.io/images/logo/logo-64.png</iconUrl>
<licenseUrl>https://github.com/zzzprojects/effort/blob/develop/LICENSE</licenseUrl>
Expand Down
Binary file modified Main/Source/.vs/Effort.EF6/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Main/Source/.vs/Effort/v15/Server/sqlite3/storage.ide
Binary file not shown.
5 changes: 5 additions & 0 deletions Main/Source/Effort.Lab.EF6/Effort.Lab.EF6.csproj
Expand Up @@ -37,6 +37,10 @@
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="NMemory, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46696d54971e6d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Build\Packages\Library\.NET 4.5\Entity Framework 6\NMemory.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
Expand All @@ -63,6 +67,7 @@
<Compile Include="Form_Request_LazyLoading.Designer.cs">
<DependentUpon>Form_Request_LazyLoading.cs</DependentUpon>
</Compile>
<Compile Include="My.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="__Form_Template.cs">
Expand Down
21 changes: 15 additions & 6 deletions Main/Source/Effort.Lab.EF6/Form_Request_LazyLoading.cs
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Windows.Forms;

Expand All @@ -11,7 +13,7 @@ public partial class Form_Request_LazyLoading : Form
public Form_Request_LazyLoading()
{
InitializeComponent();

var connection = DbConnectionFactory.CreateTransient();

// CLEAN
Expand All @@ -28,8 +30,8 @@ public Form_Request_LazyLoading()
var entity1 = context.EntitySimples.Add(new EntitySimple {ColumnInt = 1, EntitySimpleLazy = new List<EntitySimpleLazy>()});
entity1.EntitySimpleLazy.Add(new EntitySimpleLazy {ColumnInt = 10});
entity1.EntitySimpleLazy.Add(new EntitySimpleLazy {ColumnInt = 20});
context.EntitySimples.Add(new EntitySimple {ColumnInt = 2});
context.EntitySimples.Add(new EntitySimple {ColumnInt = 3});
context.EntitySimples.Add(new EntitySimple {ColumnInt = 2, ColumnGuid = Guid.NewGuid()});
context.EntitySimples.Add(new EntitySimple {ColumnInt = 3, ColumnGuid = Guid.NewGuid() });
context.SaveChanges();

// Proxy type are not created since entities (without proxy) already exists in the context
Expand All @@ -39,16 +41,21 @@ public Form_Request_LazyLoading()
// TEST
using (var context = new EntityContext(connection))
{
var anotherGuid = Guid.NewGuid();

// Proxy type are created since entities are loaded from the memory
var list = context.EntitySimples.ToList();
var list = context.EntitySimples
.Where(x => x.ColumnGuid.CompareTo(anotherGuid) >= 0)
.ToList();
}
}

public class EntityContext : DbContext
{
public EntityContext(DbConnection connection) : base(connection, true)
{
//this.Configuration.LazyLoadingEnabled = true;
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}

public DbSet<EntitySimple> EntitySimples { get; set; }
Expand All @@ -71,6 +78,8 @@ public class EntitySimple
public int ID { get; set; }
public int ColumnInt { get; set; }

public Guid ColumnGuid { get; set; }

public virtual ICollection<EntitySimpleLazy> EntitySimpleLazy { get; set; }
}

Expand Down
14 changes: 14 additions & 0 deletions Main/Source/Effort.Lab.EF6/My.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Effort.Lab.EF6
{
public static class My
{
public static Func<SqlConnection> ConnectionFactory = () => new SqlConnection("Server=XPS8700;Initial Catalog=Z.Test.EntityFramework.Plus.EF6;Integrated Security=true;Connection Timeout=300;Persist Security Info=True");
}
}
38 changes: 20 additions & 18 deletions Main/Source/Effort.sln
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Effort", "Effort\Effort.csproj", "{E612D252-9081-4995-B717-5DBEF8240FB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Effort.Test", "Effort.Test\Effort.Test.csproj", "{368B9C8C-234A-4D63-BF17-22C87A126EB6}"
Expand All @@ -22,42 +24,42 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{BDA2CB
EndProjectSection
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Effort.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_net45|Any CPU = Debug_net45|Any CPU
Debug_net40|Any CPU = Debug_net40|Any CPU
Release_net45|Any CPU = Release_net45|Any CPU
Debug_net45|Any CPU = Debug_net45|Any CPU
Release_net40|Any CPU = Release_net40|Any CPU
Release_net45|Any CPU = Release_net45|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E612D252-9081-4995-B717-5DBEF8240FB6}.Debug_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Debug_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Debug_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Debug_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net40|Any CPU.ActiveCfg = Release_ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net40|Any CPU.Build.0 = Release_ef6_net40|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net45|Any CPU.ActiveCfg = Release_ef6_net45|Any CPU
{E612D252-9081-4995-B717-5DBEF8240FB6}.Release_net45|Any CPU.Build.0 = Release_ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Debug_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Debug_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Debug_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Debug_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net40|Any CPU.ActiveCfg = Release_ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net40|Any CPU.Build.0 = Release_ef6_net40|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net45|Any CPU.ActiveCfg = Release_ef6_net45|Any CPU
{368B9C8C-234A-4D63-BF17-22C87A126EB6}.Release_net45|Any CPU.Build.0 = Release_ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Debug_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Debug_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Debug_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Debug_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net40|Any CPU.ActiveCfg = Debug_pre-ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net40|Any CPU.Build.0 = Debug_pre-ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net45|Any CPU.ActiveCfg = Debug_pre-ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net45|Any CPU.Build.0 = Debug_pre-ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net40|Any CPU.ActiveCfg = Release_ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net40|Any CPU.Build.0 = Release_ef6_net40|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net45|Any CPU.ActiveCfg = Release_ef6_net45|Any CPU
{0FC240A8-7D16-4F3F-BB4E-73DB0E398928}.Release_net45|Any CPU.Build.0 = Release_ef6_net45|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Effort.vsmdi
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions Main/Source/Effort/Effort.csproj
Expand Up @@ -129,6 +129,7 @@
<Compile Include="Internal\DbCommandTreeTransformation\Functions\DoubleFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\DecimalFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\IntegerFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\GuidFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\StringFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\DateTimeOffsetFunctions.cs" />
<Compile Include="Internal\DbCommandTreeTransformation\Functions\TimeFunctions.cs" />
Expand Down
Expand Up @@ -215,7 +215,7 @@ public static string Concat(string a, string b)
return null;
}

return string.Concat(a, b);
return String.Concat(a, b);
}

public static bool? Contains(string a, string b)
Expand Down Expand Up @@ -1027,6 +1027,25 @@ internal static int CompareTo(string a, string b)

#endregion

#region Guid

internal static int CompareTo(Guid? a, Guid? b)
{
if (a == null && b == null)
{
return 0;
}

if (a == null || b == null)
{
return -1;
}

return a.Value.CompareTo(b.Value);
}

#endregion

#region Time

public static TimeSpan? CreateTime(
Expand Down Expand Up @@ -1210,7 +1229,7 @@ public static string ToString(object obj)
{
var format = CultureInfo.InvariantCulture;

return string.Format(format, "{0}", obj);
return String.Format(format, "{0}", obj);
}

public static T? TryParse<T>(string s) where T : struct
Expand Down
@@ -0,0 +1,36 @@
// --------------------------------------------------------------------------------------------
// <copyright file="StringFunctions.cs" company="Effort Team">
// Copyright (C) Effort Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------

namespace Effort.Internal.DbCommandTreeTransformation.Functions
{
using System;
using System.Reflection;
using Effort.Internal.Common;

internal class GuidFunctions
{
public static readonly MethodInfo CompareTo =
ReflectionHelper.GetMethodInfo(() => DbFunctions.CompareTo(Guid.Empty, Guid.Empty));
}
}
Expand Up @@ -53,6 +53,11 @@ private Expression CreateComparison(Expression left, Expression right, DbExpress
return CreateStringComparison(left, right, kind);
}

else if (left.Type == typeof(Guid?) && right.Type == typeof(Guid?))
{
return CreateGuidComparison(left, right, kind);
}

switch (kind)
{
case DbExpressionKind.Equals:
Expand Down Expand Up @@ -94,6 +99,21 @@ private Expression CreateStringComparison(Expression left, Expression right, DbE
return res;
}

private Expression CreateGuidComparison(Expression left, Expression right, DbExpressionKind kind)
{
var method = Expression.Call(null, GuidFunctions.CompareTo, left, right);
var mode = GetCompareMode(kind);

Expression res = Expression.Equal(method, Expression.Constant(mode.Item1));

if (!mode.Item2)
{
res = Expression.Not(res);
}

return res;
}

private Tuple<int, bool> GetCompareMode(DbExpressionKind kind)
{
switch (kind)
Expand Down
5 changes: 2 additions & 3 deletions Main/Source/Effort/Properties/AssemblyVersion.cs
Expand Up @@ -23,7 +23,6 @@
// --------------------------------------------------------------------------------------------

using System.Reflection;
using System.Runtime.CompilerServices;

// Version information for an assembly consists of the following four values:
//
Expand All @@ -36,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.3.1")]
[assembly: AssemblyInformationalVersion("1.3.1")]
[assembly: AssemblyFileVersion("1.3.2")]
[assembly: AssemblyInformationalVersion("1.3.2")]

0 comments on commit 6bec953

Please sign in to comment.