diff --git a/src/EFCore.Jet/EFCore.Jet.csproj b/src/EFCore.Jet/EFCore.Jet.csproj
index e1f4f96..a5f3947 100644
--- a/src/EFCore.Jet/EFCore.Jet.csproj
+++ b/src/EFCore.Jet/EFCore.Jet.csproj
@@ -159,6 +159,7 @@
+
diff --git a/src/EFCore.Jet/Extensions/JetServiceCollectionExtensions.cs b/src/EFCore.Jet/Extensions/JetServiceCollectionExtensions.cs
index 2468a66..d82bab3 100644
--- a/src/EFCore.Jet/Extensions/JetServiceCollectionExtensions.cs
+++ b/src/EFCore.Jet/Extensions/JetServiceCollectionExtensions.cs
@@ -3,6 +3,7 @@
using EntityFrameworkCore.Jet.Infrastructure.Internal;
using EntityFrameworkCore.Jet.Internal;
using EntityFrameworkCore.Jet.Metadata.Conventions;
+using EntityFrameworkCore.Jet.Metadata.Internal;
using EntityFrameworkCore.Jet.Migrations;
using EntityFrameworkCore.Jet.Migrations.Internal;
using EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal;
@@ -21,6 +22,7 @@ using Microsoft.EntityFrameworkCore.Query.Sql;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Update;
using EntityFrameworkCore.Jet.Utilities;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.ValueGeneration;
using Microsoft.Extensions.DependencyInjection;
@@ -71,6 +73,9 @@ namespace Extensions.DependencyInjection
.TryAdd>()
.TryAdd(p => p.GetService())
.TryAdd()
+
+ .TryAdd()
+
.TryAdd()
.TryAdd()
.TryAdd()
diff --git a/src/EFCore.Jet/Metadata/Internal/JetEntityMaterializerSource.cs b/src/EFCore.Jet/Metadata/Internal/JetEntityMaterializerSource.cs
new file mode 100644
index 0000000..7c2f0d2
--- /dev/null
+++ b/src/EFCore.Jet/Metadata/Internal/JetEntityMaterializerSource.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Jet;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using Microsoft.EntityFrameworkCore.Internal;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
+using Microsoft.EntityFrameworkCore.Storage;
+
+namespace EntityFrameworkCore.Jet.Metadata.Internal
+{
+ public class JetEntityMaterializerSource : EntityMaterializerSource
+ {
+ public override Expression CreateReadValueExpression(
+ Expression valueBuffer,
+ Type type,
+ int index,
+ IProperty property)
+ => Expression.Call(
+ TryReadValueMethod.MakeGenericMethod(type),
+ valueBuffer,
+ Expression.Constant(index),
+ Expression.Constant(property, typeof(IPropertyBase)));
+
+ ///
+ /// This API supports the Entity Framework Core infrastructure and is not intended to be used
+ /// directly from your code. This API may change or be removed in future releases.
+ ///
+ public override Expression CreateMaterializeExpression(
+ IEntityType entityType,
+ Expression valueBufferExpression,
+ int[] indexMap = null)
+ {
+ // ReSharper disable once SuspiciousTypeConversion.Global
+ var materializer = entityType as IEntityMaterializer;
+
+ if (materializer != null)
+ {
+ return Expression.Call(
+ Expression.Constant(materializer),
+ ((Func)materializer.CreateEntity).GetMethodInfo(),
+ valueBufferExpression);
+ }
+
+ if (!entityType.HasClrType())
+ {
+ throw new InvalidOperationException(CoreStrings.NoClrType(entityType.DisplayName()));
+ }
+
+ if (entityType.IsAbstract())
+ {
+ throw new InvalidOperationException(CoreStrings.CannotMaterializeAbstractType(entityType));
+ }
+
+ var constructorInfo = entityType.ClrType.GetDeclaredConstructor(null);
+
+ if (constructorInfo == null)
+ {
+ throw new InvalidOperationException(CoreStrings.NoParameterlessConstructor(entityType.DisplayName()));
+ }
+
+ var instanceVariable = Expression.Variable(entityType.ClrType, "instance");
+
+ var blockExpressions
+ = new List
+ {
+ Expression.Assign(
+ instanceVariable,
+ Expression.New(constructorInfo))
+ };
+
+ blockExpressions.AddRange(
+ from property in entityType.GetProperties().Where(p => !p.IsShadowProperty)
+ let targetMember = Expression.MakeMemberAccess(
+ instanceVariable,
+ property.GetMemberInfo(forConstruction: true, forSet: true))
+ select
+ Expression.Assign(
+ targetMember,
+ CreateReadValueExpression(
+ valueBufferExpression,
+ targetMember.Type,
+ indexMap?[property.GetIndex()] ?? property.GetIndex(),
+ property)));
+
+ blockExpressions.Add(instanceVariable);
+
+ return Expression.Block(new[] { instanceVariable }, blockExpressions);
+ }
+
+ public override Expression CreateReadValueCallExpression(Expression valueBuffer, int index)
+ {
+ return base.CreateReadValueCallExpression(valueBuffer, index);
+ }
+
+ public override Func GetMaterializer(IEntityType entityType)
+ {
+ return base.GetMaterializer(entityType);
+ }
+
+ ///
+ /// This API supports the Entity Framework Core infrastructure and is not intended to be used
+ /// directly from your code. This API may change or be removed in future releases.
+ ///
+ public new static readonly MethodInfo TryReadValueMethod
+ = typeof(JetEntityMaterializerSource).GetTypeInfo()
+ .GetDeclaredMethod(nameof(TryReadValue));
+
+
+ private static TValue TryReadValue(
+ ValueBuffer valueBuffer,
+ int index,
+ IPropertyBase property = null)
+ {
+ object untypedValue = valueBuffer[index];
+
+ try
+ {
+ if (untypedValue != null && !typeof(TValue).IsAssignableFrom(untypedValue.GetType()))
+ {
+ if (typeof(TValue).IsAssignableFrom(typeof(TimeSpan)))
+ untypedValue = ((DateTime)untypedValue - JetConfiguration.TimeSpanOffset);
+ if (typeof(TValue).IsAssignableFrom(typeof(bool)))
+ untypedValue = Convert.ToBoolean(untypedValue);
+ }
+
+ return (TValue)untypedValue;
+ }
+ catch (Exception e)
+ {
+ ThrowReadValueExceptionMethod.MakeGenericMethod(typeof(TValue)).Invoke(null, new[] {e, untypedValue, property});
+ }
+
+ return default(TValue);
+ }
+
+
+
+ }
+}
diff --git a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetConvertTranslator.cs b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetConvertTranslator.cs
index 30750cd..62e45ae 100644
--- a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetConvertTranslator.cs
+++ b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetConvertTranslator.cs
@@ -53,7 +53,8 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// directly from your code. This API may change or be removed in future releases.
///
public virtual Expression Translate(MethodCallExpression methodCallExpression)
- => _supportedMethods.Contains(methodCallExpression.Method)
+ {
+ return _supportedMethods.Contains(methodCallExpression.Method)
? new SqlFunctionExpression(
"CONVERT",
methodCallExpression.Type,
@@ -64,5 +65,6 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
methodCallExpression.Arguments[0]
})
: null;
+ }
}
}
diff --git a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetObjectToStringTranslator.cs b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetObjectToStringTranslator.cs
index ba7a618..bdc6cb4 100644
--- a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetObjectToStringTranslator.cs
+++ b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetObjectToStringTranslator.cs
@@ -56,12 +56,12 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
.UnwrapEnumType(),
out storeType))
{
+
return new SqlFunctionExpression(
- functionName: "CONVERT",
+ functionName: "Str",
returnType: methodCallExpression.Type,
arguments: new[]
{
- new SqlFragmentExpression(storeType),
methodCallExpression.Object
});
}
diff --git a/src/EFCore.Jet/Storage/Internal/JetTimeSpanTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetTimeSpanTypeMapping.cs
index 6a4d1bd..00cc0c1 100644
--- a/src/EFCore.Jet/Storage/Internal/JetTimeSpanTypeMapping.cs
+++ b/src/EFCore.Jet/Storage/Internal/JetTimeSpanTypeMapping.cs
@@ -1,7 +1,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System;
using System.Data;
using System.Data.Common;
+using System.Data.Jet;
using System.Data.OleDb;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage;
@@ -25,5 +27,10 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
((OleDbParameter)parameter).OleDbType = OleDbType.DBTimeStamp;
}
}
+
+ protected override string GenerateNonNullSqlLiteral(object value)
+ {
+ return string.Format("{0:#MM/dd/yyyy hh:mm:ss#}", JetConfiguration.TimeSpanOffset + (TimeSpan)value);
+ }
}
}
diff --git a/src/System.Data.Jet/JetCommand.cs b/src/System.Data.Jet/JetCommand.cs
index afaef82..8e91e4a 100644
--- a/src/System.Data.Jet/JetCommand.cs
+++ b/src/System.Data.Jet/JetCommand.cs
@@ -308,28 +308,17 @@ namespace System.Data.Jet
ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText);
ApplyParameters(newCommandText, _WrappedCommand.Parameters, out newCommandText);
+ DbCommand command;
+ command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
+ command.CommandText = newCommandText;
+ command.Parameters.Clear();
+
if (skipCount != 0)
- {
- DbCommand command;
- command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
- command.CommandText = newCommandText;
return new JetDataReader(command.ExecuteReader(behavior), topCount - skipCount, skipCount);
- }
- if (topCount >= 0)
- {
- DbCommand command;
- command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
- command.CommandText = newCommandText;
+ else if (topCount >= 0)
return new JetDataReader(command.ExecuteReader(behavior), topCount, 0);
- }
else
- {
- DbCommand command;
- command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
- command.CommandText = newCommandText;
return new JetDataReader(command.ExecuteReader(behavior));
- }
-
}
private int InternalExecuteNonQuery(string commandText)
@@ -345,6 +334,8 @@ namespace System.Data.Jet
DbCommand command;
command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
command.CommandText = newCommandText;
+ command.Parameters.Clear();
+
return command.ExecuteNonQuery();
}
@@ -402,6 +393,8 @@ namespace System.Data.Jet
#region TOP clause
var indexOfTop = newCommandText.IndexOf(" top ", StringComparison.InvariantCultureIgnoreCase);
+ if (indexOfTop > 12)
+ indexOfTop = -1;
topCount = -1;
skipCount = 0;
diff --git a/src/System.Data.Jet/JetParameterHelper.cs b/src/System.Data.Jet/JetParameterHelper.cs
index 74e528d..7c9bb91 100644
--- a/src/System.Data.Jet/JetParameterHelper.cs
+++ b/src/System.Data.Jet/JetParameterHelper.cs
@@ -12,7 +12,13 @@ namespace System.Data.Jet
else if (IsString(parameter))
return String.Format("'{0}'", parameter.Value);
else if (IsDateTime(parameter))
- return String.Format("#{0:yyyy-MM-ddTHH:mm:ssZ}#", parameter.Value);
+ {
+ if (parameter.Value is TimeSpan)
+ return String.Format("#{0:c}#", parameter.Value);
+ else
+ return String.Format("#{0:yyyy-MM-ddTHH:mm:ssZ}#", parameter.Value);
+
+ }
else if (IsTimeSpan(parameter))
return String.Format("#{0:c}#", parameter.Value);
else if (IsGuid(parameter))
@@ -42,7 +48,7 @@ namespace System.Data.Jet
else if (IsString(parameter))
return String.Format("'{0}'", ((string)parameter.Value).Replace("'", "''"));
else if (IsDateTime(parameter))
- return String.Format("#{0:MM/dd/yyyy HH:mm:ss}#", parameter.Value);
+ return String.Format("#{0:MM/dd/yyyy HH:mm:ss}#", parameter.Value is TimeSpan ? JetConfiguration.TimeSpanOffset + (TimeSpan)parameter.Value : parameter.Value);
else if (IsTimeSpan(parameter))
return String.Format("#{0:MM/dd/yyyy HH:mm:ss}#", JetConfiguration.TimeSpanOffset + (TimeSpan)parameter.Value);
else if (IsGuid(parameter))
diff --git a/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj b/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj
index 3366fa2..6c62e46 100644
--- a/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj
+++ b/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj
@@ -152,6 +152,7 @@
+
@@ -304,11 +305,6 @@
-
-
-
-
-
@@ -342,16 +338,11 @@
-
-
-
-
-
@@ -361,10 +352,6 @@
-
-
-
-
@@ -430,7 +417,6 @@
Always
-
diff --git a/test/EFCore.Jet.Integration.Test/Model06_Inherit/Test.cs b/test/EFCore.Jet.Integration.Test/Model06_Inherit/Test.cs
index a3ccf69..3618943 100644
--- a/test/EFCore.Jet.Integration.Test/Model06_Inherit/Test.cs
+++ b/test/EFCore.Jet.Integration.Test/Model06_Inherit/Test.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EFCore.Jet.Integration.Test.Model06_Inherit
@@ -32,7 +33,11 @@ namespace EFCore.Jet.Integration.Test.Model06_Inherit
base.CreateContext();
{
- User user = Context.Users.First(u => u.Id == userId);
+ User user = Context
+ .Users
+ .Include(_ => _.Address)
+ .First(u => u.Id == userId);
+
Console.WriteLine("{0} {1}", user.Firstname, user.Address.City);
user.Address.City = "Bologna";
@@ -43,7 +48,11 @@ namespace EFCore.Jet.Integration.Test.Model06_Inherit
base.CreateContext();
{
- User user = Context.Users.First(u => u.Id == userId);
+ User user = Context
+ .Users
+ .Include(_ => _.Address)
+ .First(u => u.Id == userId);
+
Console.WriteLine("{0} {1}", user.Firstname, user.Address.City);
}
diff --git a/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Context.cs b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Context.cs
index 9a6b9ff..49bf372 100644
--- a/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Context.cs
@@ -10,5 +10,15 @@ namespace EFCore.Jet.Integration.Test.Model12_ComplexType
public DbSet Friends { get; set; }
public DbSet LessThanFriends { get; set; }
+
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+
+ modelBuilder.Entity()
+ .OwnsOne(_ => _.Address);
+ modelBuilder.Entity()
+ .OwnsOne(_ => _.Address);
+ }
}
}
diff --git a/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Model.cs b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Model.cs
index d98e733..12b2773 100644
--- a/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/Model.cs
@@ -29,17 +29,25 @@ namespace EFCore.Jet.Integration.Test.Model12_ComplexType
}
- [ComplexType]
public class CityAddress
{
public string Cap { get; set; }
public string City { get; set; }
}
- [ComplexType]
- public class FullAddress : CityAddress
+ public class FullAddress
{
+ public string Cap { get; set; }
+ public string City { get; set; }
public string Street { get; set; }
}
+
+ /*
+ Actually complex types cannot inherit from other types
+ public class FullAddress : CityAddress
+ {
+ public string Street { get; set; }
+ }
+ */
}
diff --git a/test/EFCore.Jet.Integration.Test/Model12_ComplexType/README.cs b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/README.cs
new file mode 100644
index 0000000..78046ba
--- /dev/null
+++ b/test/EFCore.Jet.Integration.Test/Model12_ComplexType/README.cs
@@ -0,0 +1,15 @@
+/*
+Actually complex types cannot inherit from other types
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EFCore.Jet.Integration.Test.Model12_ComplexType
+{
+ class README
+ {
+ }
+}
diff --git a/test/EFCore.Jet.Integration.Test/Model16_OwnCollection/BloggingContext.cs b/test/EFCore.Jet.Integration.Test/Model16_OwnCollection/BloggingContext.cs
index e080916..2891571 100644
--- a/test/EFCore.Jet.Integration.Test/Model16_OwnCollection/BloggingContext.cs
+++ b/test/EFCore.Jet.Integration.Test/Model16_OwnCollection/BloggingContext.cs
@@ -6,8 +6,8 @@ namespace EFCore.Jet.Integration.Test.Model16_OwnCollection
{
public class BloggingContext : DbContext
{
- public BloggingContext(DbConnection connection)
- : base(new DbContextOptionsBuilder().UseJet(connection).Options)
+ public BloggingContext(DbContextOptions options)
+ : base(options)
{}
// For migration test
diff --git a/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/Model.cs b/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/Model.cs
index 8d0fa4b..a936b97 100644
--- a/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/Model.cs
@@ -7,10 +7,15 @@ namespace EFCore.Jet.Integration.Test.Model18_CompositeKeys
public class GoodsIssueProcess
{
- [Key, Column(Order = 1), MaxLength(128)]
+ // Composite keys on EF core must be configured using Fluent API
+ //[Key]
+ [Column(Order = 1)]
+ [MaxLength(128)]
public string DeliveryNote { get; set; }
- [Key, Column(Order = 2), ForeignKey("Product")]
+ //[Key]
+ [Column(Order = 2)]
+ [ForeignKey("Product")]
public int ProductId { get; set; }
public Product Product { get; set; }
}
diff --git a/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/TestContext.cs b/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/TestContext.cs
index 2b22b63..359b513 100644
--- a/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/TestContext.cs
+++ b/test/EFCore.Jet.Integration.Test/Model18_CompositeKeys/TestContext.cs
@@ -19,6 +19,9 @@ namespace EFCore.Jet.Integration.Test.Model18_CompositeKeys
modelBuilder.Entity()
.HasAlternateKey(_ => _.ArticleNumber);
+
+ modelBuilder.Entity()
+ .HasKey(_ => new {_.DeliveryNote, _.ProductId});
}
}
}
diff --git a/test/EFCore.Jet.Integration.Test/Model34_JetEfBug/Context.cs b/test/EFCore.Jet.Integration.Test/Model34_JetEfBug/Context.cs
index 77e0ee3..304a25a 100644
--- a/test/EFCore.Jet.Integration.Test/Model34_JetEfBug/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model34_JetEfBug/Context.cs
@@ -6,7 +6,8 @@ namespace EFCore.Jet.Integration.Test.Model34_JetEfBug
{
public class DataContext : DbContext
{
- public DataContext(DbConnection connection) : base(new DbContextOptionsBuilder().UseJet(connection).Options) { }
+ public DataContext(DbContextOptions options) :
+ base(options) { }
public DbSet Categories { get; set; }
public DbSet- Items { get; set; }
}
diff --git a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Context.cs b/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Context.cs
deleted file mode 100644
index f07b938..0000000
--- a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Context.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore;
-
-namespace EFCore.Jet.Integration.Test.Model36_DetachedScenario
-{
- public class Context : DbContext
- {
- public Context(DbContextOptions options) : base(options)
- {
- }
-
- public DbSet Holders { get; set; }
- public DbSet Things { get; set; }
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity()
- .HasOne(_ => _.Thing)
- .WithMany(_ => _.Holders)
- .HasForeignKey(_ => new[] {"ThingId"});
- }
- }
-}
diff --git a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/JetTest.cs b/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/JetTest.cs
deleted file mode 100644
index 10abc29..0000000
--- a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/JetTest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Data.Common;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace EFCore.Jet.Integration.Test.Model36_DetachedScenario
-{
- [TestClass]
- public class Model36_DetachedScenarioJetTest : Test
- {
- protected override DbConnection GetConnection()
- {
- return Helpers.GetJetConnection();
- }
- }
-}
diff --git a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Model.cs b/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Model.cs
deleted file mode 100644
index e5c45f8..0000000
--- a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Model.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-
-namespace EFCore.Jet.Integration.Test.Model36_DetachedScenario
-{
- public class Holder
- {
- public int Id { get; set; }
- [MaxLength(50)]
- public string Some { get; set; }
- [MaxLength(50)]
- [Required]
- public string Some2 { get; set; }
- public Thing Thing { get; set; }
-
- public override string ToString()
- {
- return string.Format("Id:{0}, Some:{1}, Thing:{2}", Id, Some, Thing);
- }
- }
-
- public class Thing
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public virtual ICollection Holders { get; set; }
-
- public override string ToString()
- {
- return string.Format("Id:{0}, Name:{1}", Id, Name);
- }
-
- }
-}
diff --git a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Repository.cs b/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Repository.cs
deleted file mode 100644
index e4162a3..0000000
--- a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Repository.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-
-namespace EFCore.Jet.Integration.Test.Model36_DetachedScenario
-{
- static class Repository
- {
- public static void Update(Context Context, Holder holder)
- {
- var thing = holder.Thing;
- holder.Thing = new Thing() {Id = 2};
- var attachedHolder = Context.Holders.Attach(holder);
- attachedHolder.Entity.Thing = thing;
- Context.Entry(holder).Property("Some").IsModified = true;
-
- //var manager = ((IObjectContextAdapter)Context).ObjectContext.ObjectStateManager;
- //manager.ChangeRelationshipState(holder, holder.Thing, "Thing", EntityState.Added);
-
- Context.SaveChanges();
- }
-
-
-
- }
-
-}
\ No newline at end of file
diff --git a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Test.cs b/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Test.cs
deleted file mode 100644
index f7effe7..0000000
--- a/test/EFCore.Jet.Integration.Test/Model36_DetachedScenario/Test.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-using System;
-using System.Data.Common;
-using System.Linq;
-using EntityFrameworkCore.Jet;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace EFCore.Jet.Integration.Test.Model36_DetachedScenario
-{
- public abstract class Test : TestBase
- {
-
- [TestMethod]
- // Validation now is done using validation Context
- /*
- [ExpectedException(typeof(DbEntityValidationException))]
- */
- public void Model36_DetachedScenarioRun()
- {
- using (DbConnection connection = GetConnection())
- {
- Seed(connection);
-
- ShowHoldersId(connection);
-
- ShowHolders(connection);
-
- base.DisposeContext();
- base.CreateContext();
-
- {
- Holder holder = new Holder()
- {
- Id = 1,
- Some = "Holder updated",
- Thing = new Thing() { Id = 2 }
- };
-
- Repository.Update(Context, holder);
- }
-
- ShowHolders(connection);
-
- Console.WriteLine("========== ATTACHED UPDATE =============");
-
- base.DisposeContext();
- base.CreateContext();
-
- {
- Holder holder = Context.Holders.First();
- holder.Thing = new Thing() { Id = 4 };
- Context.SaveChanges();
- }
-
- ShowHolders(connection);
- }
- }
-
- private static void ShowHolders(DbConnection connection)
- {
- using (var Context = new Context(new DbContextOptionsBuilder().UseJet(connection).Options))
- {
- foreach (var holder in Context.Holders.AsQueryable().Include(_ => _.Thing).ToList())
- Console.WriteLine(holder);
- }
- }
-
- private static void ShowHoldersId(DbConnection connection)
- {
- using (var Context = new Context(new DbContextOptionsBuilder().UseJet(connection).Options))
- {
- foreach (var holder in Context.Holders.Select(_ => _.Id).ToList())
- Console.WriteLine(holder);
- }
- }
-
-
- public static void Seed(DbConnection connection)
- {
- using (var Context = new Context(new DbContextOptionsBuilder().UseJet(connection).Options))
- {
- Holder holder = new Holder()
- {
- Some = "Holder 1"
- };
-
- Context.Holders.Add(holder);
-
- for (int i = 0; i < 3; i++)
- {
- Thing thing = new Thing()
- {
- Name = string.Format("Thing {0}", i + 1)
- };
- Context.Things.Add(thing);
- }
-
- Context.SaveChanges();
-
- }
- }
-
- }
-}
diff --git a/test/EFCore.Jet.Integration.Test/Model39_DetachedEntities/Test.cs b/test/EFCore.Jet.Integration.Test/Model39_DetachedEntities/Test.cs
index c710ef0..53fa432 100644
--- a/test/EFCore.Jet.Integration.Test/Model39_DetachedEntities/Test.cs
+++ b/test/EFCore.Jet.Integration.Test/Model39_DetachedEntities/Test.cs
@@ -11,7 +11,6 @@ namespace EFCore.Jet.Integration.Test.Model39_DetachedEntities
{
[TestMethod]
- [ExpectedException(typeof(DbUpdateConcurrencyException))]
public void Model39_DetachedEntitiesRun1()
{
base.DisposeContext();
@@ -68,7 +67,8 @@ namespace EFCore.Jet.Integration.Test.Model39_DetachedEntities
base.CreateContext();
{
- Grade grade = Context.Grades.Include(g => g.GradeWidths).AsNoTracking().First();
+ int gradeId = Context.Grades.First().Id;
+ Grade grade = Context.Grades.Include(g => g.GradeWidths).Where(_ => _.Id == gradeId).AsNoTracking().First();
// We need to reset all the ids
grade.Id = 0;
diff --git a/test/EFCore.Jet.Integration.Test/Model41/Check.cs b/test/EFCore.Jet.Integration.Test/Model41/Check.cs
index 4780462..b1b3921 100644
--- a/test/EFCore.Jet.Integration.Test/Model41/Check.cs
+++ b/test/EFCore.Jet.Integration.Test/Model41/Check.cs
@@ -71,8 +71,11 @@ namespace EFCore.Jet.Integration.Test.Model41
modelBuilder.Entity().HasKey(k => k.Id);
modelBuilder.Entity().HasKey(k => k.Id);
- modelBuilder.Entity().Property(_ => _.Applicant).IsRequired();
- modelBuilder.Entity().HasOne(_ => _.Applicant).WithMany(_ => _.Addresses).HasForeignKey(a => a.Applicant_Id);
+ modelBuilder.Entity()
+ .HasOne(_ => _.Applicant)
+ .WithMany(_ => _.Addresses)
+ .IsRequired()
+ .HasForeignKey(a => a.Applicant_Id);
}
}
diff --git a/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Context.cs b/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Context.cs
index b5ab105..d39355e 100644
--- a/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Context.cs
@@ -16,6 +16,10 @@ namespace EFCore.Jet.Integration.Test.Model43_PKasFK
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
+
+ modelBuilder.Entity()
+ .HasKey(_ => new {_.ParentName, _.ChildName});
+
modelBuilder.Entity()
.HasMany(_ => _.Children)
.WithOne(_ => _.Parent)
diff --git a/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Model.cs b/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Model.cs
index 5c9d3df..d2f3b3c 100644
--- a/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model43_PKasFK/Model.cs
@@ -15,11 +15,12 @@ namespace EFCore.Jet.Integration.Test.Model43_PKasFK
public class Child
{
- [Key]
+ // Multiple keys can be defined only via FluentApi
+ //[Key]
[Column(Order = 1)]
public string ParentName { get; set; }
- [Key]
+ //[Key]
[Column(Order = 2)]
public string ChildName { get; set; }
diff --git a/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Context.cs b/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Context.cs
index f92b6aa..e6b68fa 100644
--- a/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Context.cs
@@ -16,6 +16,11 @@ namespace EFCore.Jet.Integration.Test.Model46_InnerClasses
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
+ modelBuilder.Entity()
+ .OwnsOne(_ => _.B);
+ modelBuilder.Entity()
+ .OwnsOne(_ => _.C);
+
}
}
}
diff --git a/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Model.cs b/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Model.cs
index 91331f6..ba98ffd 100644
--- a/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model46_InnerClasses/Model.cs
@@ -21,13 +21,11 @@ namespace EFCore.Jet.Integration.Test.Model46_InnerClasses
public virtual ClassB B { get; set; }
public virtual ClassC C { get; set; }
- [ComplexType]
public class ClassB
{
public int? b { get; set; }
}
- [ComplexType]
public class ClassC
{
public int? c { get; set; }
diff --git a/test/EFCore.Jet.Integration.Test/Model47_200/Context.cs b/test/EFCore.Jet.Integration.Test/Model47_200/Context.cs
index 6bb96ea..14f8b3a 100644
--- a/test/EFCore.Jet.Integration.Test/Model47_200/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model47_200/Context.cs
@@ -18,12 +18,9 @@ namespace EFCore.Jet.Integration.Test.Model47_200
{
modelBuilder.Entity()
.HasOne(_ => _.Manager)
- .WithOne(_ => _.Department);
-
- modelBuilder.Entity()
- .Property(_ => _.Manager).IsRequired();
- modelBuilder.Entity()
- .Property(_ => _.Department).IsRequired();
+ .WithOne(_ => _.Department)
+ .HasForeignKey()
+ .IsRequired();
}
}
diff --git a/test/EFCore.Jet.Integration.Test/Model47_200/MyContext.cs b/test/EFCore.Jet.Integration.Test/Model47_200/MyContext.cs
deleted file mode 100644
index b4a70a4..0000000
--- a/test/EFCore.Jet.Integration.Test/Model47_200/MyContext.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore;
-
-namespace EFCore.Jet.Integration.Test.Model47_200
-{
- class MyContext : DbContext
- {
- public string Schema { get; private set; }
-
- public MyContext(string schema) : base()
- {
-
- }
-
- // Your DbSets here
- DbSet Emps { get; set; }
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity()
- .ToTable("Emps", Schema);
- }
- }
-}
diff --git a/test/EFCore.Jet.Integration.Test/Model49_Inheritance_EagerlyLoad/README.cs b/test/EFCore.Jet.Integration.Test/Model49_Inheritance_EagerlyLoad/README.cs
new file mode 100644
index 0000000..29a1603
--- /dev/null
+++ b/test/EFCore.Jet.Integration.Test/Model49_Inheritance_EagerlyLoad/README.cs
@@ -0,0 +1,12 @@
+/*
+
+This model is too complex
+
+*/
+
+namespace EFCore.Jet.Integration.Test.Model49_Inheritance_EagerlyLoad
+{
+ class README
+ {
+ }
+}
diff --git a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Context.cs b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Context.cs
index 1a5ec4c..a6b5244 100644
--- a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Context.cs
+++ b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Context.cs
@@ -17,7 +17,7 @@ namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
- .HasKey(t => t.PersonID);
+ .HasKey(t => t.PersonId);
modelBuilder.Entity()
.HasOne(t => t.City)
.WithMany()
@@ -25,13 +25,19 @@ namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
modelBuilder.Entity()
.HasOne(t => t.Address)
- .WithOne(t => t.Person)
- ;
+ .WithOne(t => t.Person);
+
modelBuilder.Entity()
- .Property(t => t.Address).IsRequired();
- modelBuilder.Entity()
- .Property(t => t.Person).IsRequired();
- ;
+ .Property(_ => _.PersonId)
+ .ValueGeneratedOnAdd();
+ modelBuilder.Entity()
+ .HasKey(_ => _.PersonId);
+
+
+ modelBuilder.Entity()
+ .Property("AddressId").IsRequired();
+
+
modelBuilder.Entity().ToTable("TB_PERSON");
diff --git a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Model.cs b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Model.cs
index 5bed325..6e74efd 100644
--- a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Model.cs
@@ -1,16 +1,17 @@
using System;
+using System.ComponentModel.DataAnnotations.Schema;
namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
{
public class Person
{
- public int PersonID { get; set; }
+ public int PersonId { get; set; }
public string Name { get; set; }
public virtual Address Address { get; set; }
}
public class Address
{
- public Int32 PersonID { get; set; }
+ public Int32 PersonId { get; set; }
public string Province { get; set; }
public virtual Person Person { get; set; }
public virtual City City { get; set; }
diff --git a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Test.cs b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Test.cs
index f202808..96bde49 100644
--- a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Test.cs
+++ b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/Test.cs
@@ -11,7 +11,7 @@ namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
public void Model53_TableSplittingRun()
{
Context.Persons.Add(
- new Person() {Name = "Bubi", Address = new Address() {Province = "MO", City = new City() {Name = "Maranello"}}}
+ new Person() {PersonId = 1, Name = "Bubi", Address = new Address() {Province = "MO", City = new City() {Name = "Maranello"}}}
);
Context.SaveChanges();
diff --git a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/readme.txt b/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/readme.txt
deleted file mode 100644
index 9215328..0000000
--- a/test/EFCore.Jet.Integration.Test/Model53_TableSplitting/readme.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-This is a solution for "Complex type cannot contain navigation properties"
-https://msdn.microsoft.com/en-us/library/bb738472.aspx
-http://stackoverflow.com/questions/42403179/how-do-i-have-class-properties-with-navigational-props-as-entity-properties-c
-
-With this model, also removing the navigation property from Address to Person (with complex type you don't have this feature), you need to have an Address class for each entity that use it (for example one for Person like in this case, one for Customer and so on).
diff --git a/test/EFCore.Jet.Integration.Test/Model71_MasterDetail/README.cs b/test/EFCore.Jet.Integration.Test/Model71_MasterDetail/README.cs
new file mode 100644
index 0000000..fbdad63
--- /dev/null
+++ b/test/EFCore.Jet.Integration.Test/Model71_MasterDetail/README.cs
@@ -0,0 +1,16 @@
+/*
+This test is based on lazy load and is not implemented in EF core 2.0
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace EFCore.Jet.Integration.Test.Model71_MasterDetail
+{
+ class README
+ {
+ }
+}
diff --git a/test/EFCore.Jet.Integration.Test/Model72_TableSplitting/Model.cs b/test/EFCore.Jet.Integration.Test/Model72_TableSplitting/Model.cs
index 788a325..34fbb51 100644
--- a/test/EFCore.Jet.Integration.Test/Model72_TableSplitting/Model.cs
+++ b/test/EFCore.Jet.Integration.Test/Model72_TableSplitting/Model.cs
@@ -1,9 +1,11 @@
using System;
+using System.ComponentModel.DataAnnotations.Schema;
namespace EFCore.Jet.Integration.Test.Model72_TableSplitting
{
//Mapped to a table, has foreign key (eg. customerId)
+ [Table("Product72")]
public class Product
{
public int Id { get; set; }
diff --git a/test/EFCore.Jet.Integration.Test/TestBase`.cs b/test/EFCore.Jet.Integration.Test/TestBase`.cs
index 4d82392..9e8b3b1 100644
--- a/test/EFCore.Jet.Integration.Test/TestBase`.cs
+++ b/test/EFCore.Jet.Integration.Test/TestBase`.cs
@@ -92,12 +92,14 @@ namespace EFCore.Jet.Integration.Test
public static DbContextOptions GetContextOptions(DbConnection dbConnection)
{
+ var optionsBuilder = new DbContextOptionsBuilder().EnableSensitiveDataLogging();
+
if (dbConnection is SqlCeConnection)
- return new DbContextOptionsBuilder().UseSqlCe(dbConnection).Options;
+ return optionsBuilder.UseSqlCe(dbConnection).Options;
else if (dbConnection is JetConnection)
- return new DbContextOptionsBuilder().UseJet(dbConnection).Options;
+ return optionsBuilder.UseJet(dbConnection).Options;
else if (dbConnection is SqlConnection)
- return new DbContextOptionsBuilder().UseSqlServer(dbConnection).Options;
+ return optionsBuilder.UseSqlServer(dbConnection).Options;
else
{
throw new InvalidOperationException("Connection type " + dbConnection.GetType().Name + " not handled");