Fixed tests

2.2-servicing
bubibubi 8 years ago
parent 8a6676904e
commit 4d131f7f65

@ -159,6 +159,7 @@
<Compile Include="Metadata\IJetModelAnnotations.cs" />
<Compile Include="Metadata\IJetPropertyAnnotations.cs" />
<Compile Include="Metadata\Internal\JetAnnotationNames.cs" />
<Compile Include="Metadata\Internal\JetEntityMaterializerSource.cs" />
<Compile Include="Metadata\Internal\JetEntityTypeBuilderAnnotations.cs" />
<Compile Include="Metadata\Internal\JetIndexBuilderAnnotations.cs" />
<Compile Include="Metadata\Internal\JetInternalMetadataBuilderExtensions.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<IDatabaseProvider, DatabaseProvider<JetOptionsExtension>>()
.TryAdd<IValueGeneratorCache>(p => p.GetService<IJetValueGeneratorCache>())
.TryAdd<IRelationalTypeMapper, JetTypeMapper>()
.TryAdd<IEntityMaterializerSource, JetEntityMaterializerSource>()
.TryAdd<ISqlGenerationHelper, JetSqlGenerationHelper>()
.TryAdd<IMigrationsAnnotationProvider, JetMigrationsAnnotationProvider>()
.TryAdd<IRelationalValueBufferFactoryFactory, UntypedRelationalValueBufferFactoryFactory>()

@ -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)));
/// <summary>
/// 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.
/// </summary>
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<ValueBuffer, object>)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>
{
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<ValueBuffer, object> GetMaterializer(IEntityType entityType)
{
return base.GetMaterializer(entityType);
}
/// <summary>
/// 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.
/// </summary>
public new static readonly MethodInfo TryReadValueMethod
= typeof(JetEntityMaterializerSource).GetTypeInfo()
.GetDeclaredMethod(nameof(TryReadValue));
private static TValue TryReadValue<TValue>(
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);
}
}
}

@ -53,7 +53,8 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
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;
}
}
}

@ -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
});
}

@ -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);
}
}
}

@ -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;

@ -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))

@ -152,6 +152,7 @@
<Compile Include="DmlSqlTest.cs" />
<Compile Include="DmlJetTest.cs" />
<Compile Include="Model04\SqlCeTest.cs" />
<Compile Include="Model12_ComplexType\README.cs" />
<Compile Include="Model37_2Contexts\SqlServerTest.cs" />
<Compile Include="Model37_2Contexts\SqlCeTest.cs" />
<Compile Include="Model44_CaseSensitivity\SqlCeTest.cs" />
@ -304,11 +305,6 @@
<Compile Include="Model35_OneToZeroOneDeleteCascade\Mappings.cs" />
<Compile Include="Model35_OneToZeroOneDeleteCascade\Model.cs" />
<Compile Include="Model35_OneToZeroOneDeleteCascade\Test.cs" />
<Compile Include="Model36_DetachedScenario\Context.cs" />
<Compile Include="Model36_DetachedScenario\JetTest.cs" />
<Compile Include="Model36_DetachedScenario\Model.cs" />
<Compile Include="Model36_DetachedScenario\Repository.cs" />
<Compile Include="Model36_DetachedScenario\Test.cs" />
<Compile Include="Model37_2Contexts\Context1.cs" />
<Compile Include="Model37_2Contexts\Context2.cs" />
<Compile Include="Model37_2Contexts\JetTest.cs" />
@ -342,16 +338,11 @@
<Compile Include="Model47_200\Context.cs" />
<Compile Include="Model47_200\JetTest.cs" />
<Compile Include="Model47_200\Model.cs" />
<Compile Include="Model47_200\MyContext.cs" />
<Compile Include="Model47_200\Test.cs" />
<Compile Include="Model48_Cast\Context.cs" />
<Compile Include="Model48_Cast\JetTest.cs" />
<Compile Include="Model48_Cast\Model.cs" />
<Compile Include="Model48_Cast\Test.cs" />
<Compile Include="Model49_Inheritance_EagerlyLoad\Context.cs" />
<Compile Include="Model49_Inheritance_EagerlyLoad\JetTest.cs" />
<Compile Include="Model49_Inheritance_EagerlyLoad\Model.cs" />
<Compile Include="Model49_Inheritance_EagerlyLoad\Test.cs" />
<Compile Include="Model51_1_Many_RemoveChildren\Context.cs" />
<Compile Include="Model51_1_Many_RemoveChildren\JetTest.cs" />
<Compile Include="Model51_1_Many_RemoveChildren\Model.cs" />
@ -361,10 +352,6 @@
<Compile Include="Model53_TableSplitting\Model.cs" />
<Compile Include="Model53_TableSplitting\Test.cs" />
<Compile Include="Model54_MemoryLeakageTest\Test.cs" />
<Compile Include="Model71_MasterDetail\Context.cs" />
<Compile Include="Model71_MasterDetail\JetTest.cs" />
<Compile Include="Model71_MasterDetail\Model.cs" />
<Compile Include="Model71_MasterDetail\Test.cs" />
<Compile Include="Model70_InMemoryObjectPartialUpdate\Context.cs" />
<Compile Include="Model70_InMemoryObjectPartialUpdate\JetTest.cs" />
<Compile Include="Model70_InMemoryObjectPartialUpdate\Model.cs" />
@ -430,7 +417,6 @@
<Content Include="Empty.accdb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Model53_TableSplitting\readme.txt" />
</ItemGroup>
<ItemGroup>
<Folder Include="obj\" />

@ -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);
}

@ -10,5 +10,15 @@ namespace EFCore.Jet.Integration.Test.Model12_ComplexType
public DbSet<Friend> Friends { get; set; }
public DbSet<LessThanFriend> LessThanFriends { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Friend>()
.OwnsOne(_ => _.Address);
modelBuilder.Entity<LessThanFriend>()
.OwnsOne(_ => _.Address);
}
}
}

@ -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; }
}
*/
}

@ -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
{
}
}

@ -6,8 +6,8 @@ namespace EFCore.Jet.Integration.Test.Model16_OwnCollection
{
public class BloggingContext : DbContext
{
public BloggingContext(DbConnection connection)
: base(new DbContextOptionsBuilder<BloggingContext>().UseJet(connection).Options)
public BloggingContext(DbContextOptions options)
: base(options)
{}
// For migration test

@ -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; }
}

@ -19,6 +19,9 @@ namespace EFCore.Jet.Integration.Test.Model18_CompositeKeys
modelBuilder.Entity<Product>()
.HasAlternateKey(_ => _.ArticleNumber);
modelBuilder.Entity<GoodsIssueProcess>()
.HasKey(_ => new {_.DeliveryNote, _.ProductId});
}
}
}

@ -6,7 +6,8 @@ namespace EFCore.Jet.Integration.Test.Model34_JetEfBug
{
public class DataContext : DbContext
{
public DataContext(DbConnection connection) : base(new DbContextOptionsBuilder<DataContext>().UseJet(connection).Options) { }
public DataContext(DbContextOptions options) :
base(options) { }
public DbSet<Category> Categories { get; set; }
public DbSet<Item> Items { get; set; }
}

@ -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<Holder> Holders { get; set; }
public DbSet<Thing> Things { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Holder>()
.HasOne(_ => _.Thing)
.WithMany(_ => _.Holders)
.HasForeignKey(_ => new[] {"ThingId"});
}
}
}

@ -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();
}
}
}

@ -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<Holder> Holders { get; set; }
public override string ToString()
{
return string.Format("Id:{0}, Name:{1}", Id, Name);
}
}
}

@ -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();
}
}
}

@ -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<Context>
{
[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<Context>().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<Context>().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<Context>().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();
}
}
}
}

@ -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;

@ -71,8 +71,11 @@ namespace EFCore.Jet.Integration.Test.Model41
modelBuilder.Entity<Applicant>().HasKey(k => k.Id);
modelBuilder.Entity<Applicant_Address>().HasKey(k => k.Id);
modelBuilder.Entity<Applicant_Address>().Property(_ => _.Applicant).IsRequired();
modelBuilder.Entity<Applicant_Address>().HasOne(_ => _.Applicant).WithMany(_ => _.Addresses).HasForeignKey(a => a.Applicant_Id);
modelBuilder.Entity<Applicant_Address>()
.HasOne(_ => _.Applicant)
.WithMany(_ => _.Addresses)
.IsRequired()
.HasForeignKey(a => a.Applicant_Id);
}
}

@ -16,6 +16,10 @@ namespace EFCore.Jet.Integration.Test.Model43_PKasFK
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Child>()
.HasKey(_ => new {_.ParentName, _.ChildName});
modelBuilder.Entity<Parent>()
.HasMany(_ => _.Children)
.WithOne(_ => _.Parent)

@ -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; }

@ -16,6 +16,11 @@ namespace EFCore.Jet.Integration.Test.Model46_InnerClasses
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ClassA>()
.OwnsOne(_ => _.B);
modelBuilder.Entity<ClassA>()
.OwnsOne(_ => _.C);
}
}
}

@ -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; }

@ -18,12 +18,9 @@ namespace EFCore.Jet.Integration.Test.Model47_200
{
modelBuilder.Entity<Dept>()
.HasOne(_ => _.Manager)
.WithOne(_ => _.Department);
modelBuilder.Entity<Dept>()
.Property(_ => _.Manager).IsRequired();
modelBuilder.Entity<Emp>()
.Property(_ => _.Department).IsRequired();
.WithOne(_ => _.Department)
.HasForeignKey<Dept>()
.IsRequired();
}
}

@ -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<Emp> Emps { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Emp>()
.ToTable("Emps", Schema);
}
}
}

@ -0,0 +1,12 @@
/*
This model is too complex
*/
namespace EFCore.Jet.Integration.Test.Model49_Inheritance_EagerlyLoad
{
class README
{
}
}

@ -17,7 +17,7 @@ namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Address>()
.HasKey(t => t.PersonID);
.HasKey(t => t.PersonId);
modelBuilder.Entity<Address>()
.HasOne(t => t.City)
.WithMany()
@ -25,13 +25,19 @@ namespace EFCore.Jet.Integration.Test.Model53_TableSplitting
modelBuilder.Entity<Person>()
.HasOne(t => t.Address)
.WithOne(t => t.Person)
;
.WithOne(t => t.Person);
modelBuilder.Entity<Person>()
.Property(t => t.Address).IsRequired();
modelBuilder.Entity<Address>()
.Property(t => t.Person).IsRequired();
;
.Property(_ => _.PersonId)
.ValueGeneratedOnAdd();
modelBuilder.Entity<Person>()
.HasKey(_ => _.PersonId);
modelBuilder.Entity<Person>()
.Property<int>("AddressId").IsRequired();
modelBuilder.Entity<Person>().ToTable("TB_PERSON");

@ -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; }

@ -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();

@ -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).

@ -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
{
}
}

@ -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; }

@ -92,12 +92,14 @@ namespace EFCore.Jet.Integration.Test
public static DbContextOptions GetContextOptions(DbConnection dbConnection)
{
var optionsBuilder = new DbContextOptionsBuilder<T>().EnableSensitiveDataLogging();
if (dbConnection is SqlCeConnection)
return new DbContextOptionsBuilder<T>().UseSqlCe(dbConnection).Options;
return optionsBuilder.UseSqlCe(dbConnection).Options;
else if (dbConnection is JetConnection)
return new DbContextOptionsBuilder<T>().UseJet(dbConnection).Options;
return optionsBuilder.UseJet(dbConnection).Options;
else if (dbConnection is SqlConnection)
return new DbContextOptionsBuilder<T>().UseSqlServer(dbConnection).Options;
return optionsBuilder.UseSqlServer(dbConnection).Options;
else
{
throw new InvalidOperationException("Connection type " + dbConnection.GetType().Name + " not handled");

Loading…
Cancel
Save