Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3c692bb
Fix an issue where we were always using the (changeable) static varia…
lauxjpn Jan 19, 2020
25f8685
Use `DbConnectionStringBuilder` instead of its OleDb equivalent.
lauxjpn Jan 20, 2020
47d677d
Revert "Use `DbConnectionStringBuilder` instead of its OleDb equivale…
lauxjpn Feb 24, 2020
e3d4027
Merge remote-tracking branch 'freddy/EFCore3.1_Test' into upgrade
lauxjpn Feb 24, 2020
985f618
Adjust solution and project files. Replace occurrences of "SQL Server…
lauxjpn Feb 26, 2020
0ee60b5
Upgrade infrastructure and internal files to 3.1.x.
lauxjpn Feb 26, 2020
9fe1e40
Update shared files to 3.1.x.
lauxjpn Feb 26, 2020
ba29bf2
Upgrade diagnostics related files to 3.1.x.
lauxjpn Feb 26, 2020
f469233
Upgrade design related files to 3.1.x.
lauxjpn Feb 26, 2020
8ccf288
Upgrade properties related files to 3.1.x.
lauxjpn Mar 1, 2020
885cbb4
Upgrade diagnostics files to 3.1.x.
lauxjpn Mar 9, 2020
d7df27a
Upgrade infrastructure and internal files to 3.1.x.
lauxjpn Mar 1, 2020
05ba7de
Upgrade value generation files to 3.1.x.
lauxjpn Mar 1, 2020
6e8cc34
Upgrade storage files to 3.1.x.
lauxjpn Mar 1, 2020
70f2b88
Upgrade sql update generation files to 3.1.x.
lauxjpn Mar 1, 2020
6fffce9
Upgrade scaffolding related files to 3.1.x.
lauxjpn Mar 1, 2020
a4328da
Upgrade migration related files to 3.1.x.
lauxjpn Mar 1, 2020
5829ca8
Upgrade query pipeline to 3.1.x.
lauxjpn Mar 8, 2020
24bf603
Remove obsolete files.
lauxjpn Mar 9, 2020
108a3be
Update and fix smaller System.Data.Jet issues.
lauxjpn Mar 9, 2020
1be52ee
Update and fix dependencies.
lauxjpn Mar 9, 2020
0c2fbad
Remove obsolete files.
lauxjpn Mar 10, 2020
583f990
Upgrade and fix System.Data.Jet and System.Data.Jet.Test to 3.1.x.
lauxjpn Mar 10, 2020
66b7124
Upgrade and fix EFCore.Jet.Integration.Test to 3.1.x.
lauxjpn Mar 11, 2020
a59af50
Upgrade EFCore.Jet.IntegrationTests.
lauxjpn Mar 17, 2020
afd9d85
Remove obsolete tests.
lauxjpn Mar 17, 2020
2eef0b9
Remove obsolete design tests.
lauxjpn Mar 17, 2020
5de0755
Upgrade System.Data.Jet.Test.
lauxjpn Mar 17, 2020
74dd677
Upgrade EFCore.Jet.FunctionalTests.
lauxjpn Mar 18, 2020
24f9708
Fix issues in System.Data.Jet and implement dynamic COM object handling.
lauxjpn Mar 18, 2020
e040941
Fix issues in EFCore.Jet and simplify query generation based on tests.
lauxjpn Mar 18, 2020
a71fcc1
Update solution and build/infrastructure files.
lauxjpn Mar 18, 2020
b117d4e
Cleanup code, remove dummy transaction and add missing Dispose() meth…
lauxjpn Mar 23, 2020
71b5410
Fix dispose pattern for releasing the RCW object.
lauxjpn Mar 23, 2020
e6c100e
Switch to multi-targeting.
lauxjpn Mar 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issues in EFCore.Jet and simplify query generation based on tests.
  • Loading branch information
lauxjpn committed Mar 23, 2020
commit e0409411c93147aac0bdb6470ecd9ccc8e46ec91
11 changes: 11 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<Import Project="..\Directory.Build.props" />

<PropertyGroup>
<IsPackable>True</IsPackable>
<IncludeSymbols>True</IncludeSymbols>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\build\Key.snk</AssemblyOriginatorKeyFile>
<EmbedUntrackedSources>True</EmbedUntrackedSources>
</PropertyGroup>
</Project>
14 changes: 0 additions & 14 deletions src/EFCore.Jet/EFCore.Jet.csproj
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<DefaultNetCoreTargetFramework>netcoreapp3.1</DefaultNetCoreTargetFramework>
<DefaultNetStandardTargetFramework>netstandard2.0</DefaultNetStandardTargetFramework>
</PropertyGroup>

<Import Project="..\..\build\Dependencies.props" />
<Import Project="..\..\build\Development.props" Condition="Exists('..\..\build\Development.props')" />

<PropertyGroup>
<TargetFramework>$(DefaultNetStandardTargetFramework)</TargetFramework>
<LangVersion>8.0</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>EntityFrameworkCore.Jet</RootNamespace>
<AssemblyName>EntityFrameworkCore.Jet</AssemblyName>
<Platforms>AnyCPU;x86;x64</Platforms>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\build\Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\Shared\Check.cs">
<Link>Check.cs</Link>
</Compile>
Expand Down
508 changes: 508 additions & 0 deletions src/EFCore.Jet/Extensions/JetDbFunctionsExtensions.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static IServiceCollection AddEntityFrameworkJet([NotNull] this IServiceCo
.TryAdd<IMemberTranslatorProvider, JetMemberTranslatorProvider>()
.TryAdd<IQuerySqlGeneratorFactory, JetQuerySqlGeneratorFactory>()
.TryAdd<ISqlExpressionFactory, JetSqlExpressionFactory>()
.TryAdd<IQueryTranslationPostprocessorFactory, JetQueryTranslationPostprocessorFactory>()
.TryAddProviderSpecificServices(
b => b
.TryAddSingleton<IJetOptions, JetOptions>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
Expand Down
3 changes: 0 additions & 3 deletions src/EFCore.Jet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Reflection;
using Microsoft.EntityFrameworkCore.Design;

[assembly: DesignTimeProviderServices("EntityFrameworkCore.Jet.Design.Internal.JetDesignTimeServices")]
[assembly: AssemblyTitle("EntityFrameworkCore.Jet")]
[assembly: AssemblyDescription("Jet (Microsoft Access mdb or accdb files) provider for Entity Framework Core (EFCore)")]
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ public class JetConvertTranslator : IMethodCallTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;

// The value here is actually never used.
private static readonly Dictionary<string, string> _functionName = new Dictionary<string, string>
{
[nameof(Convert.ToByte)] = "CByte",
[nameof(Convert.ToDecimal)] = "CCur", // CDec does not work https://docs.microsoft.com/en-us/office/troubleshoot/access/cdec-function-error
[nameof(Convert.ToSingle)] = "CSng",
[nameof(Convert.ToDouble)] = "CDbl",
[nameof(Convert.ToInt16)] = "CInt",
[nameof(Convert.ToInt32)] = "CLng",
// [nameof(Convert.ToInt64)] = "CDec", // CDec does not work https://docs.microsoft.com/en-us/office/troubleshoot/access/cdec-function-error
[nameof(Convert.ToString)] = "CStr"
[nameof(Convert.ToBoolean)] = "CBOOL",
[nameof(Convert.ToByte)] = "CBYTE",
[nameof(Convert.ToInt16)] = "CINT",
[nameof(Convert.ToInt32)] = "CLNG",
// [nameof(Convert.ToInt64)] = "CDEC", // CDEC does not work https://docs.microsoft.com/en-us/office/troubleshoot/access/cdec-function-error
[nameof(Convert.ToDecimal)] = "CCUR", // CDEC does not work https://docs.microsoft.com/en-us/office/troubleshoot/access/cdec-function-error
[nameof(Convert.ToSingle)] = "CSNG",
[nameof(Convert.ToDouble)] = "CDBL",
[nameof(Convert.ToDateTime)] = "CDATE",
[nameof(Convert.ToString)] = "CSTR"
};

private static readonly List<Type> _supportedTypes = new List<Type>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;

namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
{
public class JetDateDiffFunctionsTranslator : IMethodCallTranslator
{
private readonly Dictionary<MethodInfo, string> _methodInfoDateDiffMapping
= new Dictionary<MethodInfo, string>
{
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffYear),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"yyyy"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffYear),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"yyyy"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffYear),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"yyyy"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffYear),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"yyyy"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMonth),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"m"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMonth),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"m"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMonth),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"m"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMonth),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"m"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffDay),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"d"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffDay),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"d"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffDay),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"d"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffDay),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"d"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffHour),
new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) }),
"h"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffMinute),
new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) }),
"n"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) }),
"s"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) }),
"s"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) }),
"s"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) }),
"s"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) }),
"s"
},
{
typeof(JetDbFunctionsExtensions).GetRuntimeMethod(
nameof(JetDbFunctionsExtensions.DateDiffSecond),
new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) }),
"s"
},
};

private readonly ISqlExpressionFactory _sqlExpressionFactory;

public JetDateDiffFunctionsTranslator(
ISqlExpressionFactory sqlExpressionFactory)
{
_sqlExpressionFactory = sqlExpressionFactory;
}

public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
{
if (_methodInfoDateDiffMapping.TryGetValue(method, out var datePart))
{
var startDate = arguments[1];
var endDate = arguments[2];
var typeMapping = ExpressionExtensions.InferTypeMapping(startDate, endDate);

startDate = _sqlExpressionFactory.ApplyTypeMapping(startDate, typeMapping);
endDate = _sqlExpressionFactory.ApplyTypeMapping(endDate, typeMapping);

return _sqlExpressionFactory.Function(
"DATEDIFF",
new[] { _sqlExpressionFactory.Constant(datePart), startDate, endDate },
typeof(int));
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type r
{
return member.Name switch
{
nameof(DateTime.Now) => _sqlExpressionFactory.Function("Now", Array.Empty<SqlExpression>(), returnType),
nameof(DateTime.UtcNow) => _sqlExpressionFactory.Function("Now", Array.Empty<SqlExpression>(), returnType),
nameof(DateTime.Now) => _sqlExpressionFactory.Function("NOW", Array.Empty<SqlExpression>(), returnType),
nameof(DateTime.UtcNow) => _sqlExpressionFactory.Function("NOW", Array.Empty<SqlExpression>(), returnType),
_ => null,
};
}

return member.Name switch
{
nameof(DateTime.Today) => _sqlExpressionFactory.Function(
"DateValue",
new[] {_sqlExpressionFactory.Function("Now", Array.Empty<SqlExpression>(), returnType)},
"DATEVALUE",
new[] {_sqlExpressionFactory.Function("NOW", Array.Empty<SqlExpression>(), returnType)},
returnType),

nameof(DateTime.Year) => GetDatePartExpression(instance, returnType, "yyyy"),
Expand All @@ -58,16 +58,16 @@ public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type r
GetDatePartExpression(instance, returnType, "w"),
_sqlExpressionFactory.Constant(1)),

nameof(DateTime.Date) => _sqlExpressionFactory.JetNullChecked(
nameof(DateTime.Date) => _sqlExpressionFactory.NullChecked(
instance,
_sqlExpressionFactory.Function(
"DateValue",
"DATEVALUE",
new[] {instance},
returnType)),
nameof(DateTime.TimeOfDay) => _sqlExpressionFactory.JetNullChecked(
nameof(DateTime.TimeOfDay) => _sqlExpressionFactory.NullChecked(
instance,
_sqlExpressionFactory.Function(
"TimeValue",
"TIMEVALUE",
new[] {instance},
returnType)),

Expand All @@ -83,7 +83,7 @@ private SqlExpression GetDatePartExpression(
string datePart)
{
return _sqlExpressionFactory.Function(
"DatePart",
"DATEPART",
new[]
{
_sqlExpressionFactory.Constant(datePart),
Expand Down
Loading