diff --git a/EntityFramework.sln.DotSettings b/EntityFramework.sln.DotSettings
index c7349a1e226..fd54373ce0f 100644
--- a/EntityFramework.sln.DotSettings
+++ b/EntityFramework.sln.DotSettings
@@ -49,6 +49,7 @@
True
True
+ 140
False
True
diff --git a/src/EntityFramework.Core/EntityFramework.Core.csproj b/src/EntityFramework.Core/EntityFramework.Core.csproj
index 8a9a5dc0ce2..141ae504a5f 100644
--- a/src/EntityFramework.Core/EntityFramework.Core.csproj
+++ b/src/EntityFramework.Core/EntityFramework.Core.csproj
@@ -29,7 +29,7 @@
pdbonly
true
bin\Release\
- TRACE;CSPROJ
+ TRACE;CSPROJ;NET451
prompt
4
true
@@ -86,6 +86,8 @@
+
+
@@ -492,4 +494,4 @@
-->
-
+
\ No newline at end of file
diff --git a/src/EntityFramework.Core/Infrastructure/Annotatable.cs b/src/EntityFramework.Core/Infrastructure/Annotatable.cs
index 98e0a35f13b..0c506eb56ec 100644
--- a/src/EntityFramework.Core/Infrastructure/Annotatable.cs
+++ b/src/EntityFramework.Core/Infrastructure/Annotatable.cs
@@ -3,79 +3,103 @@
using System;
using System.Collections.Generic;
-using System.Collections.Immutable;
+using System.Linq;
using JetBrains.Annotations;
using Microsoft.Data.Entity.Internal;
+using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Infrastructure
{
///
///
- /// Base class for types that support reading and writing annotations.
+ /// Base class for types that support reading and writing annotations.
///
///
/// This type is typically used by database providers (and other extensions). It is generally
/// not used in application code.
///
///
- public class Annotatable : IAnnotatable
+ public class Annotatable : IMutableAnnotatable
{
- // TODO: Perf: use a mutable structure before the model is made readonly
- // Issue #868
- private readonly LazyRef> _annotations
- = new LazyRef>(
- () => ImmutableSortedSet.Empty.WithComparer(new AnnotationComparer()));
+ private readonly LazyRef> _annotations =
+ new LazyRef>(() => new SortedDictionary());
+
+ ///
+ /// Gets all annotations on the current object.
+ ///
+ public virtual IEnumerable GetAnnotations() =>
+ _annotations.HasValue
+ ? _annotations.Value.Values
+ : Enumerable.Empty();
///
/// Adds an annotation to this object. Throws if an annotation with the specified name already exists.
///
- /// The key of the annotation to be added.
+ /// The key of the annotation to be added.
/// The value to be stored in the annotation.
/// The newly added annotation.
- public virtual Annotation AddAnnotation([NotNull] string annotationName, [NotNull] object value)
+ public virtual Annotation AddAnnotation(string name, object value)
{
- Check.NotEmpty(annotationName, nameof(annotationName));
+ Check.NotEmpty(name, nameof(name));
Check.NotNull(value, nameof(value));
- var annotation = new Annotation(annotationName, value);
+ var annotation = CreateAnnotation(name, value);
+ return AddAnnotation(name, annotation);
+ }
+
+ protected virtual Annotation AddAnnotation([NotNull] string name, [NotNull] Annotation annotation)
+ {
var previousLength = _annotations.Value.Count;
- _annotations.Value = _annotations.Value.Add(annotation);
+ SetAnnotation(name, annotation);
if (previousLength == _annotations.Value.Count)
{
- throw new InvalidOperationException(CoreStrings.DuplicateAnnotation(annotationName));
+ throw new InvalidOperationException(CoreStrings.DuplicateAnnotation(name));
}
return annotation;
}
+ protected virtual Annotation SetAnnotation([NotNull] string name, [NotNull] Annotation annotation)
+ {
+ _annotations.Value[name] = annotation;
+
+ return annotation;
+ }
+
///
- /// Adds an annotation to this object or returns the existing annotation if one with the specified name already exists.
+ /// Adds an annotation to this object or returns the existing annotation if one with the specified name
+ /// already exists.
///
- /// The key of the annotation to be added.
+ /// The key of the annotation to be added.
/// The value to be stored in the annotation.
- ///
- /// The existing annotation if an annotation with the specified name already exists. Otherwise, the newly added annotation.
+ ///
+ /// The existing annotation if an annotation with the specified name already exists. Otherwise, the newly
+ /// added annotation.
///
- public virtual Annotation GetOrAddAnnotation([NotNull] string annotationName, [NotNull] object value)
- => FindAnnotation(annotationName) ?? AddAnnotation(annotationName, value);
+ public virtual Annotation GetOrAddAnnotation([NotNull] string name, [NotNull] object value)
+ => FindAnnotation(name) ?? AddAnnotation(name, value);
///
/// Gets the annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
+ /// The key of the annotation to find.
///
- /// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
+ /// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
- public virtual Annotation FindAnnotation([NotNull] string annotationName)
+ public virtual Annotation FindAnnotation(string name)
{
- Check.NotEmpty(annotationName, nameof(annotationName));
+ Check.NotEmpty(name, nameof(name));
+
+ if (!_annotations.HasValue)
+ {
+ return null;
+ }
Annotation annotation;
- return _annotations.HasValue
- && _annotations.Value.TryGetValue(new Annotation(annotationName, "_"), out annotation)
+ return _annotations.Value.TryGetValue(name, out annotation)
? annotation
: null;
}
@@ -83,63 +107,54 @@ public virtual Annotation FindAnnotation([NotNull] string annotationName)
///
/// Removes the given annotation from this object.
///
- /// The annotation to remove.
+ /// The annotation to remove.
/// The annotation that was removed.
- public virtual Annotation RemoveAnnotation([NotNull] string annotationName)
+ public virtual Annotation RemoveAnnotation(string name)
{
- Check.NotNull(annotationName, nameof(annotationName));
-
- var previousAnnotations = _annotations.Value;
- var annotation = new Annotation(annotationName, "_");
- _annotations.Value = _annotations.Value.Remove(annotation);
+ Check.NotNull(name, nameof(name));
- Annotation removedAnnotations = null;
- if (previousAnnotations.Count != _annotations.Value.Count)
+ var annotation = FindAnnotation(name);
+ if (annotation == null)
{
- previousAnnotations.TryGetValue(annotation, out removedAnnotations);
+ return null;
}
- return removedAnnotations;
+ _annotations.Value.Remove(name);
+
+ return annotation;
}
///
/// Gets the value annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
- ///
- /// The value of the existing annotation if an annotation with the specified name already exists. Otherwise, null.
+ /// The key of the annotation to find.
+ ///
+ /// The value of the existing annotation if an annotation with the specified name already exists.
+ /// Otherwise, null.
///
// ReSharper disable once AnnotationRedundancyInHierarchy
// TODO: Fix API test to handle indexer
- public virtual object this[[NotNull] string annotationName]
+ public virtual object this[[NotNull] string name]
{
- get { return FindAnnotation(annotationName)?.Value; }
+ get { return FindAnnotation(name)?.Value; }
[param: CanBeNull]
set
{
- Check.NotEmpty(annotationName, nameof(annotationName));
-
- _annotations.Value = _annotations.Value.Remove(new Annotation(annotationName, "_"));
+ Check.NotEmpty(name, nameof(name));
- if (value != null)
+ if (value == null)
+ {
+ RemoveAnnotation(name);
+ }
+ else
{
- AddAnnotation(annotationName, value);
+ _annotations.Value[name] = CreateAnnotation(name, value);
}
}
}
- ///
- /// Gets all annotations on the current object.
- ///
- public virtual IEnumerable GetAnnotations()
- => _annotations.HasValue
- ? (IEnumerable)_annotations.Value
- : ImmutableList.Empty;
-
- private class AnnotationComparer : IComparer
- {
- public int Compare(IAnnotation x, IAnnotation y) => StringComparer.Ordinal.Compare(x.Name, y.Name);
- }
+ protected virtual Annotation CreateAnnotation([NotNull] string name, [NotNull] object value)
+ => new Annotation(name, value);
///
/// Gets all annotations on the current object.
@@ -149,10 +164,10 @@ private class AnnotationComparer : IComparer
///
/// Gets the annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
+ /// The key of the annotation to find.
///
- /// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
+ /// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
- IAnnotation IAnnotatable.FindAnnotation(string annotationName) => FindAnnotation(annotationName);
+ IAnnotation IAnnotatable.FindAnnotation(string name) => FindAnnotation(name);
}
}
diff --git a/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs b/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs
index 9465c505020..3c59c95352c 100644
--- a/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs
+++ b/src/EntityFramework.Core/Infrastructure/IAnnotatable.cs
@@ -20,22 +20,22 @@ public interface IAnnotatable
///
/// Gets the value annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
+ /// The key of the annotation to find.
///
/// The value of the existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
// ReSharper disable once AnnotationRedundancyInHierarchy
// TODO: Fix API test to handle indexer
- object this[[NotNull] string annotationName] { get; }
+ object this[[NotNull] string name] { get; }
///
/// Gets the annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
+ /// The key of the annotation to find.
///
/// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
- IAnnotation FindAnnotation([NotNull] string annotationName);
+ IAnnotation FindAnnotation([NotNull] string name);
///
/// Gets all annotations on the current object.
diff --git a/src/EntityFramework.Core/Infrastructure/ModelSource.cs b/src/EntityFramework.Core/Infrastructure/ModelSource.cs
index 1b61a07122a..0a1ad7e65fc 100644
--- a/src/EntityFramework.Core/Infrastructure/ModelSource.cs
+++ b/src/EntityFramework.Core/Infrastructure/ModelSource.cs
@@ -66,11 +66,11 @@ protected virtual IModel CreateModel(
Check.NotNull(validator, nameof(validator));
var conventionSet = CreateConventionSet(conventionSetBuilder);
- var model = new Model();
- model.SetProductVersion(ProductInfo.GetVersion());
+ var modelBuilder = new ModelBuilder(conventionSet);
- var modelBuilder = new ModelBuilder(conventionSet, model);
+ var model = (Model)modelBuilder.Model;
+ model.SetProductVersion(ProductInfo.GetVersion());
FindSets(modelBuilder, context);
diff --git a/src/EntityFramework.Core/Metadata/Conventions/Internal/DerivedTypeDiscoveryConvention.cs b/src/EntityFramework.Core/Metadata/Conventions/Internal/DerivedTypeDiscoveryConvention.cs
index 8f1e0e98a4e..21c5f086f94 100644
--- a/src/EntityFramework.Core/Metadata/Conventions/Internal/DerivedTypeDiscoveryConvention.cs
+++ b/src/EntityFramework.Core/Metadata/Conventions/Internal/DerivedTypeDiscoveryConvention.cs
@@ -20,7 +20,8 @@ public virtual InternalEntityTypeBuilder Apply(InternalEntityTypeBuilder entityT
var directlyDerivedTypes = entityType.Model.GetEntityTypes().Where(t =>
t.BaseType == entityType.BaseType
&& t.HasClrType()
- && FindClosestBaseType(t) == entityType);
+ && FindClosestBaseType(t) == entityType)
+ .ToList();
foreach (var directlyDerivedType in directlyDerivedTypes)
{
diff --git a/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs b/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs
index 2cbefdd1a0a..350725dcc66 100644
--- a/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs
+++ b/src/EntityFramework.Core/Metadata/IMutableAnnotatable.cs
@@ -1,3 +1,6 @@
+// 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;
using JetBrains.Annotations;
using Microsoft.Data.Entity.Infrastructure;
@@ -19,13 +22,13 @@ public interface IMutableAnnotatable : IAnnotatable
///
/// Gets or sets the value of the annotation with the given name.
///
- /// The key of the annotation.
+ /// The key of the annotation.
///
/// The value of the existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
// ReSharper disable once AnnotationRedundancyInHierarchy
// TODO: Fix API test to handle indexer
- new object this[[NotNull] string annotationName] { get; [param: CanBeNull] set; }
+ new object this[[NotNull] string name] { get; [param: CanBeNull] set; }
///
/// Gets all annotations on the current object.
@@ -35,25 +38,25 @@ public interface IMutableAnnotatable : IAnnotatable
///
/// Adds an annotation to this object. Throws if an annotation with the specified name already exists.
///
- /// The key of the annotation to be added.
+ /// The key of the annotation to be added.
/// The value to be stored in the annotation.
/// The newly added annotation.
- Annotation AddAnnotation([NotNull] string annotationName, [NotNull] object value);
+ Annotation AddAnnotation([NotNull] string name, [NotNull] object value);
///
/// Gets the annotation with the given name, returning null if it does not exist.
///
- /// The key of the annotation to find.
+ /// The key of the annotation to find.
///
/// The existing annotation if an annotation with the specified name already exists. Otherwise, null.
///
- new Annotation FindAnnotation([NotNull] string annotationName);
+ new Annotation FindAnnotation([NotNull] string name);
///
/// Removes the given annotation from this object.
///
- /// The annotation to remove.
+ /// The annotation to remove.
/// The annotation that was removed.
- Annotation RemoveAnnotation([NotNull] string annotationName);
+ Annotation RemoveAnnotation([NotNull] string name);
}
}
diff --git a/src/EntityFramework.Core/Metadata/IMutableForeignKey.cs b/src/EntityFramework.Core/Metadata/IMutableForeignKey.cs
index 61df1ef98b3..e141c615196 100644
--- a/src/EntityFramework.Core/Metadata/IMutableForeignKey.cs
+++ b/src/EntityFramework.Core/Metadata/IMutableForeignKey.cs
@@ -1,3 +1,6 @@
+// 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;
using JetBrains.Annotations;
@@ -86,4 +89,4 @@ public interface IMutableForeignKey : IForeignKey, IMutableAnnotatable
///
new DeleteBehavior? DeleteBehavior { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/EntityFramework.Core/Metadata/IMutableModel.cs b/src/EntityFramework.Core/Metadata/IMutableModel.cs
index 0748ec7b7dc..8a4284954a8 100644
--- a/src/EntityFramework.Core/Metadata/IMutableModel.cs
+++ b/src/EntityFramework.Core/Metadata/IMutableModel.cs
@@ -44,6 +44,6 @@ public interface IMutableModel : IModel, IMutableAnnotatable
/// Gets all entities types defined in the model.
///
/// All entities types defined in the model.
- new IReadOnlyList GetEntityTypes();
+ new IEnumerable GetEntityTypes();
}
}
diff --git a/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotatable.cs b/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotatable.cs
new file mode 100644
index 00000000000..04103c3b963
--- /dev/null
+++ b/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotatable.cs
@@ -0,0 +1,42 @@
+// 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;
+using System.Linq;
+using JetBrains.Annotations;
+using Microsoft.Data.Entity.Infrastructure;
+
+namespace Microsoft.Data.Entity.Metadata.Internal
+{
+ public class ConventionalAnnotatable : Annotatable
+ {
+ public new virtual IEnumerable GetAnnotations() => base.GetAnnotations().Cast();
+
+ public virtual ConventionalAnnotation AddAnnotation(
+ [NotNull] string name, [NotNull] object value, ConfigurationSource configurationSource)
+ => (ConventionalAnnotation)base.AddAnnotation(name, CreateAnnotation(name, value, configurationSource));
+
+ public new virtual ConventionalAnnotation AddAnnotation([NotNull] string name, [NotNull] object value)
+ => (ConventionalAnnotation)base.AddAnnotation(name, value);
+
+ public virtual ConventionalAnnotation SetAnnotation(
+ [NotNull] string name, [NotNull] object value, ConfigurationSource configurationSource)
+ => (ConventionalAnnotation)base.SetAnnotation(name, CreateAnnotation(name, value, configurationSource));
+
+ public new virtual ConventionalAnnotation GetOrAddAnnotation([NotNull] string name, [NotNull] object value)
+ => (ConventionalAnnotation)base.GetOrAddAnnotation(name, value);
+
+ public new virtual ConventionalAnnotation FindAnnotation([NotNull] string name)
+ => (ConventionalAnnotation)base.FindAnnotation(name);
+
+ public new virtual ConventionalAnnotation RemoveAnnotation([NotNull] string name)
+ => (ConventionalAnnotation)base.RemoveAnnotation(name);
+
+ private ConventionalAnnotation CreateAnnotation(
+ string name, object value, ConfigurationSource configurationSource)
+ => new ConventionalAnnotation(name, value, configurationSource);
+
+ protected override Annotation CreateAnnotation(string name, object value)
+ => CreateAnnotation(name, value, ConfigurationSource.Explicit);
+ }
+}
diff --git a/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotation.cs b/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotation.cs
new file mode 100644
index 00000000000..3673832c41f
--- /dev/null
+++ b/src/EntityFramework.Core/Metadata/Internal/ConventionalAnnotation.cs
@@ -0,0 +1,24 @@
+// 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 JetBrains.Annotations;
+using Microsoft.Data.Entity.Infrastructure;
+
+namespace Microsoft.Data.Entity.Metadata.Internal
+{
+ public class ConventionalAnnotation : Annotation
+ {
+ private ConfigurationSource _configurationSource;
+
+ public ConventionalAnnotation([NotNull] string name, [NotNull] object value, ConfigurationSource configurationSource)
+ : base(name, value)
+ {
+ _configurationSource = configurationSource;
+ }
+
+ public virtual ConfigurationSource GetConfigurationSource() => _configurationSource;
+
+ public virtual ConfigurationSource UpdateConfigurationSource(ConfigurationSource configurationSource)
+ => _configurationSource = _configurationSource.Max(configurationSource);
+ }
+}
diff --git a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs
index d30c8f7e36c..0544771e49d 100644
--- a/src/EntityFramework.Core/Metadata/Internal/EntityType.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/EntityType.cs
@@ -7,13 +7,12 @@
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
- public class EntityType : Annotatable, IMutableEntityType, ICanGetNavigations
+ public class EntityType : ConventionalAnnotatable, IMutableEntityType, ICanGetNavigations
{
private static readonly char[] _simpleNameChars = { '.', '+' };
diff --git a/src/EntityFramework.Core/Metadata/Internal/ForeignKey.cs b/src/EntityFramework.Core/Metadata/Internal/ForeignKey.cs
index c0db7c5c5f9..c1e1cd8673e 100644
--- a/src/EntityFramework.Core/Metadata/Internal/ForeignKey.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/ForeignKey.cs
@@ -5,13 +5,12 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
- public class ForeignKey : Annotatable, IMutableForeignKey
+ public class ForeignKey : ConventionalAnnotatable, IMutableForeignKey
{
private DeleteBehavior? _deleteBehavior;
diff --git a/src/EntityFramework.Core/Metadata/Internal/Index.cs b/src/EntityFramework.Core/Metadata/Internal/Index.cs
index 4ffa5559d9d..9c2577a83a1 100644
--- a/src/EntityFramework.Core/Metadata/Internal/Index.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/Index.cs
@@ -4,13 +4,12 @@
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public class Index : Annotatable, IMutableIndex
+ public class Index : ConventionalAnnotatable, IMutableIndex
{
public Index([NotNull] IReadOnlyList properties)
{
diff --git a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs
index 741198885a4..23f1e4f12c3 100644
--- a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder.cs
@@ -1,24 +1,19 @@
// 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;
+using System.Diagnostics;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
-using Microsoft.Data.Entity.Internal;
namespace Microsoft.Data.Entity.Metadata.Internal
{
public abstract class InternalMetadataBuilder
{
- private readonly LazyRef> _annotationSources =
- new LazyRef>(() => new Dictionary());
-
- protected InternalMetadataBuilder([NotNull] Annotatable metadata)
+ protected InternalMetadataBuilder([NotNull] ConventionalAnnotatable metadata)
{
Metadata = metadata;
}
- public virtual Annotatable Metadata { get; }
+ public virtual ConventionalAnnotatable Metadata { get; }
public abstract InternalModelBuilder ModelBuilder { get; }
public virtual bool HasAnnotation(
@@ -28,34 +23,38 @@ public virtual bool HasAnnotation(
private bool HasAnnotation(
string name, object value, ConfigurationSource configurationSource, bool canOverrideSameSource)
{
- var existingValue = Metadata[name];
- if (existingValue != null)
+ var existingAnnotation = Metadata.FindAnnotation(name);
+ if (existingAnnotation != null)
{
- ConfigurationSource existingConfigurationSource;
- if (!_annotationSources.Value.TryGetValue(name, out existingConfigurationSource))
+ if (existingAnnotation.Value.Equals(value))
{
- existingConfigurationSource = ConfigurationSource.Explicit;
+ existingAnnotation.UpdateConfigurationSource(configurationSource);
+ return true;
}
- if ((value == null || !existingValue.Equals(value))
- && (!configurationSource.Overrides(existingConfigurationSource)
- || configurationSource == existingConfigurationSource && !canOverrideSameSource))
+ var existingConfigurationSource = existingAnnotation.GetConfigurationSource();
+ if (!configurationSource.Overrides(existingConfigurationSource)
+ || (configurationSource == existingConfigurationSource && !canOverrideSameSource))
{
return false;
}
- configurationSource = configurationSource.Max(existingConfigurationSource);
+ if (value == null)
+ {
+ var removed = Metadata.RemoveAnnotation(name);
+ Debug.Assert(removed == existingAnnotation);
+ }
+ else
+ {
+ Metadata.SetAnnotation(name, value, configurationSource);
+ }
+
+ return true;
}
if (value != null)
{
- _annotationSources.Value[name] = configurationSource;
- Metadata[name] = value;
- }
- else
- {
- _annotationSources.Value.Remove(name);
- Metadata.RemoveAnnotation(name);
+ Metadata.AddAnnotation(name, value, configurationSource);
}
return true;
@@ -65,16 +64,10 @@ protected virtual void MergeAnnotationsFrom([NotNull] InternalMetadataBuilder an
{
foreach (var annotation in annotatableBuilder.Metadata.GetAnnotations())
{
- ConfigurationSource annotationSource;
- if (!annotatableBuilder._annotationSources.Value.TryGetValue(annotation.Name, out annotationSource))
- {
- annotationSource = ConfigurationSource.Explicit;
- }
-
HasAnnotation(
annotation.Name,
annotation.Value,
- annotationSource,
+ annotation.GetConfigurationSource(),
canOverrideSameSource: false);
}
}
diff --git a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder`.cs b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder`.cs
index 235643cfd64..0f802be01b7 100644
--- a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder`.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataBuilder`.cs
@@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
namespace Microsoft.Data.Entity.Metadata.Internal
{
public abstract class InternalMetadataBuilder : InternalMetadataBuilder
- where TMetadata : Annotatable
+ where TMetadata : ConventionalAnnotatable
{
protected InternalMetadataBuilder([NotNull] TMetadata metadata)
: base(metadata)
diff --git a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataItemBuilder.cs b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataItemBuilder.cs
index b4bd65e32e8..958e36281d0 100644
--- a/src/EntityFramework.Core/Metadata/Internal/InternalMetadataItemBuilder.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/InternalMetadataItemBuilder.cs
@@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
namespace Microsoft.Data.Entity.Metadata.Internal
{
public abstract class InternalMetadataItemBuilder : InternalMetadataBuilder
- where TMetadata : Annotatable
+ where TMetadata : ConventionalAnnotatable
{
protected InternalMetadataItemBuilder([NotNull] TMetadata metadata, [NotNull] InternalModelBuilder modelBuilder)
: base(metadata)
diff --git a/src/EntityFramework.Core/Metadata/Internal/Key.cs b/src/EntityFramework.Core/Metadata/Internal/Key.cs
index 50e0221309b..ee5748cf838 100644
--- a/src/EntityFramework.Core/Metadata/Internal/Key.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/Key.cs
@@ -5,13 +5,12 @@
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
- public class Key : Annotatable, IMutableKey
+ public class Key : ConventionalAnnotatable, IMutableKey
{
public Key([NotNull] IReadOnlyList properties)
{
diff --git a/src/EntityFramework.Core/Metadata/Internal/Model.cs b/src/EntityFramework.Core/Metadata/Internal/Model.cs
index 4eebcaaedb8..535a4790e83 100644
--- a/src/EntityFramework.Core/Metadata/Internal/Model.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/Model.cs
@@ -3,33 +3,25 @@
using System;
using System.Collections.Generic;
-using System.Collections.Immutable;
+using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
- public class Model : Annotatable, IMutableModel
+ public class Model : ConventionalAnnotatable, IMutableModel
{
- private ImmutableSortedSet _entities
- = ImmutableSortedSet.Empty.WithComparer(new EntityTypeNameComparer());
+ private readonly SortedDictionary _entities = new SortedDictionary();
public virtual EntityType AddEntityType([NotNull] string name)
{
Check.NotEmpty(name, nameof(name));
- return AddEntityType(new EntityType(name, this));
- }
-
- public virtual EntityType AddEntityType([NotNull] Type type) => (EntityType)((IMutableModel)this).AddEntityType(type);
-
- private EntityType AddEntityType(EntityType entityType)
- {
+ var entityType = new EntityType(name, this);
var previousLength = _entities.Count;
- _entities = _entities.Add(entityType);
+ _entities[name] = entityType;
if (previousLength == _entities.Count)
{
@@ -39,6 +31,8 @@ private EntityType AddEntityType(EntityType entityType)
return entityType;
}
+ public virtual EntityType AddEntityType([NotNull] Type type) => (EntityType)((IMutableModel)this).AddEntityType(type);
+
public virtual EntityType GetOrAddEntityType([NotNull] Type type)
=> FindEntityType(type) ?? AddEntityType(type);
@@ -52,13 +46,11 @@ public virtual EntityType FindEntityType([NotNull] string name)
{
Check.NotEmpty(name, nameof(name));
- return FindEntityType(new EntityType(name, this));
- }
-
- private EntityType FindEntityType(EntityType entityType)
- => _entities.TryGetValue(entityType, out entityType)
+ EntityType entityType;
+ return _entities.TryGetValue(name, out entityType)
? entityType
: null;
+ }
public virtual EntityType RemoveEntityType([NotNull] Type type)
{
@@ -99,25 +91,19 @@ private EntityType RemoveEntityType([NotNull] EntityType entityType)
derivedEntityType.DisplayName()));
}
- var previousEntities = _entities;
- _entities = _entities.Remove(entityType);
+ var removed = _entities.Remove(entityType.Name);
+ Debug.Assert(removed);
- EntityType removedEntityType = null;
- if (previousEntities.Count != _entities.Count)
- {
- previousEntities.TryGetValue(entityType, out removedEntityType);
- }
-
- return removedEntityType;
+ return entityType;
}
- public virtual IReadOnlyList GetEntityTypes() => _entities;
+ public virtual IEnumerable GetEntityTypes() => _entities.Values;
IEntityType IModel.FindEntityType(string name) => FindEntityType(name);
IEnumerable IModel.GetEntityTypes() => GetEntityTypes();
IMutableEntityType IMutableModel.AddEntityType(string name) => AddEntityType(name);
- IReadOnlyList IMutableModel.GetEntityTypes() => GetEntityTypes();
+ IEnumerable IMutableModel.GetEntityTypes() => GetEntityTypes();
IMutableEntityType IMutableModel.FindEntityType(string name) => FindEntityType(name);
IMutableEntityType IMutableModel.RemoveEntityType(string name) => RemoveEntityType(name);
}
diff --git a/src/EntityFramework.Core/Metadata/Internal/Navigation.cs b/src/EntityFramework.Core/Metadata/Internal/Navigation.cs
index 02a63ddd3b0..fd5ff56a021 100644
--- a/src/EntityFramework.Core/Metadata/Internal/Navigation.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/Navigation.cs
@@ -7,14 +7,13 @@
using System.Reflection;
using System.Threading;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
[DebuggerDisplay("{DeclaringEntityType.Name,nq}.{Name,nq}")]
- public class Navigation : Annotatable, IMutableNavigation, INavigationAccessors
+ public class Navigation : ConventionalAnnotatable, IMutableNavigation, INavigationAccessors
{
// Warning: Never access this field directly as access needs to be thread-safe
private IClrPropertyGetter _getter;
diff --git a/src/EntityFramework.Core/Metadata/Internal/Property.cs b/src/EntityFramework.Core/Metadata/Internal/Property.cs
index e3a22f564f7..3eed6fbd470 100644
--- a/src/EntityFramework.Core/Metadata/Internal/Property.cs
+++ b/src/EntityFramework.Core/Metadata/Internal/Property.cs
@@ -8,14 +8,13 @@
using System.Reflection;
using System.Threading;
using JetBrains.Annotations;
-using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Utilities;
namespace Microsoft.Data.Entity.Metadata.Internal
{
[DebuggerDisplay("{DeclaringEntityType.Name,nq}.{Name,nq} ({ClrType?.Name,nq})")]
- public class Property : Annotatable, IMutableProperty, IPropertyBaseAccessors
+ public class Property : ConventionalAnnotatable, IMutableProperty, IPropertyBaseAccessors
{
// Warning: Never access this field directly as access needs to be thread-safe
private IClrPropertyGetter _getter;
diff --git a/src/EntityFramework.Core/ModelBuilder.cs b/src/EntityFramework.Core/ModelBuilder.cs
index 0485f7b4424..05a799ac518 100644
--- a/src/EntityFramework.Core/ModelBuilder.cs
+++ b/src/EntityFramework.Core/ModelBuilder.cs
@@ -14,12 +14,12 @@ namespace Microsoft.Data.Entity
{
///
///
- /// Provides a simple API surface for configuring a that defines the shape of your
+ /// Provides a simple API surface for configuring a that defines the shape of your
/// entities, the relationships between them, and how they map to the database.
///
///
/// You can use to construct a model for a context by overriding
- /// on your derived context. Alternatively you can create the
+ /// on your derived context. Alternatively you can create the
/// model externally and set it on a instance that is passed to the context constructor.
///
///
@@ -39,20 +39,6 @@ public ModelBuilder([NotNull] ConventionSet conventions)
_builder = new InternalModelBuilder(new Model(), conventions).Initialize();
}
- ///
- /// Initializes a new instance of the class that will
- /// configure an existing model and apply a set of conventions.
- ///
- /// The conventions to be applied to the model.
- /// The model to be configured.
- public ModelBuilder([NotNull] ConventionSet conventions, [NotNull] Model model)
- {
- Check.NotNull(model, nameof(model));
- Check.NotNull(conventions, nameof(conventions));
-
- _builder = new InternalModelBuilder(model, conventions).Initialize();
- }
-
public virtual ModelBuilder Validate()
{
Builder.Validate();
diff --git a/src/EntityFramework.Relational/Metadata/RelationalAnnotations.cs b/src/EntityFramework.Relational/Metadata/RelationalAnnotations.cs
index c1f2f399221..0c70a0bd46b 100644
--- a/src/EntityFramework.Relational/Metadata/RelationalAnnotations.cs
+++ b/src/EntityFramework.Relational/Metadata/RelationalAnnotations.cs
@@ -38,7 +38,7 @@ public virtual bool SetAnnotation([NotNull] string annotationName, [CanBeNull] o
{
Check.NotEmpty(annotationName, nameof(annotationName));
- var annotatable = Metadata as Annotatable;
+ var annotatable = Metadata as IMutableAnnotatable;
Debug.Assert(annotatable != null);
var fullName = (ProviderPrefix ?? RelationalAnnotationNames.Prefix) + annotationName;
diff --git a/src/EntityFramework.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EntityFramework.Relational/Migrations/Internal/MigrationsModelDiffer.cs
index 10d10b3f936..c3a7c01f68d 100644
--- a/src/EntityFramework.Relational/Migrations/Internal/MigrationsModelDiffer.cs
+++ b/src/EntityFramework.Relational/Migrations/Internal/MigrationsModelDiffer.cs
@@ -882,7 +882,7 @@ protected virtual bool HasDifferences([NotNull] IEnumerable source,
return unmatched.Count != 0;
}
- protected virtual void CopyAnnotations([NotNull] IEnumerable annotations, [NotNull] Annotatable annotatable)
+ protected virtual void CopyAnnotations([NotNull] IEnumerable annotations, [NotNull] IMutableAnnotatable annotatable)
{
foreach (var annotation in annotations)
{
diff --git a/test/EntityFramework.Core.FunctionalTests/TestHelpers.cs b/test/EntityFramework.Core.FunctionalTests/TestHelpers.cs
index a0379c1a911..0d52da524b9 100644
--- a/test/EntityFramework.Core.FunctionalTests/TestHelpers.cs
+++ b/test/EntityFramework.Core.FunctionalTests/TestHelpers.cs
@@ -121,7 +121,7 @@ public IMutableModel BuildModelFor() where TEntity : class
return builder.Model;
}
- public ModelBuilder CreateConventionBuilder(Model model = null)
+ public ModelBuilder CreateConventionBuilder()
{
var contextServices = CreateContextServices();
@@ -130,7 +130,7 @@ public ModelBuilder CreateConventionBuilder(Model model = null)
conventionSet = conventionSetBuilder == null
? conventionSet
: conventionSetBuilder.AddConventions(conventionSet);
- return new ModelBuilder(conventionSet, model ?? new Model());
+ return new ModelBuilder(conventionSet);
}
public InternalEntityEntry CreateInternalEntry(
diff --git a/test/EntityFramework.Core.FunctionalTests/TestModelSource.cs b/test/EntityFramework.Core.FunctionalTests/TestModelSource.cs
index 3bb18475326..e6aa49805e4 100644
--- a/test/EntityFramework.Core.FunctionalTests/TestModelSource.cs
+++ b/test/EntityFramework.Core.FunctionalTests/TestModelSource.cs
@@ -26,12 +26,11 @@ public TestModelSource(
protected override IModel CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
{
var conventionSet = CreateConventionSet(conventionSetBuilder);
- var model = new Model();
+ var modelBuilder = new ModelBuilder(conventionSet);
+ var model = (Model)modelBuilder.Model;
model.SetProductVersion(ProductInfo.GetVersion());
- var modelBuilder = new ModelBuilder(conventionSet, model);
-
FindSets(modelBuilder, context);
_onModelCreating(modelBuilder);
diff --git a/test/EntityFramework.Core.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs b/test/EntityFramework.Core.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs
index 1e34867a393..00493a0c4ea 100644
--- a/test/EntityFramework.Core.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs
+++ b/test/EntityFramework.Core.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using Microsoft.Data.Entity.ChangeTracking.Internal;
using Microsoft.Data.Entity.Metadata;
-using Microsoft.Data.Entity.Metadata.Internal;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
@@ -227,8 +226,7 @@ private class OrderLineDetail
private static IModel BuildModel()
{
- var model = new Model();
- var builder = TestHelpers.Instance.CreateConventionBuilder(model);
+ var builder = TestHelpers.Instance.CreateConventionBuilder();
builder.Entity();
@@ -252,7 +250,7 @@ private static IModel BuildModel()
b.HasOne(e => e.Detail).WithOne(e => e.OrderLine);
});
- return model;
+ return builder.Model;
}
}
}
diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs
index 07ad14f52a2..955a3c26d0f 100644
--- a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalMetadataBuilderTest.cs
@@ -9,11 +9,6 @@ namespace Microsoft.Data.Entity.Metadata.Internal
{
public class InternalMetadataBuilderTest
{
- private InternalMetadataBuilder CreateInternalMetadataBuilder()
- {
- return new InternalModelBuilder(new Model(), new ConventionSet());
- }
-
[Fact]
public void Can_only_override_lower_source_annotation()
{
@@ -59,5 +54,8 @@ public void Annotation_set_explicitly_can_not_be_removed_by_convention()
Assert.True(builder.HasAnnotation("Foo", null, ConfigurationSource.Explicit));
Assert.Equal(0, metadata.GetAnnotations().Count());
}
+
+ private InternalMetadataBuilder CreateInternalMetadataBuilder()
+ => new InternalModelBuilder(new Model(), new ConventionSet());
}
}
diff --git a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalModelBuilderTest.cs b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalModelBuilderTest.cs
index 33925b6329d..1e80b3ee625 100644
--- a/test/EntityFramework.Core.Tests/Metadata/Internal/InternalModelBuilderTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/Internal/InternalModelBuilderTest.cs
@@ -166,7 +166,7 @@ public void Can_ignore_entity_type_with_base_and_derived_types()
Assert.True(modelBuilder.Ignore(typeof(Customer), ConfigurationSource.DataAnnotation));
- Assert.Equal(2, modelBuilder.Metadata.GetEntityTypes().Count);
+ Assert.Equal(2, modelBuilder.Metadata.GetEntityTypes().Count());
Assert.Same(baseEntityTypeBuilder.Metadata, specialCustomerEntityTypeBuilder.Metadata.BaseType);
}
@@ -183,7 +183,7 @@ public void Cannot_ignore_entity_type_referenced_from_higher_source_foreign_key(
Assert.False(modelBuilder.Ignore(typeof(Customer), ConfigurationSource.DataAnnotation));
- Assert.Equal(2, modelBuilder.Metadata.GetEntityTypes().Count);
+ Assert.Equal(2, modelBuilder.Metadata.GetEntityTypes().Count());
Assert.Equal(1, orderEntityTypeBuilder.Metadata.GetForeignKeys().Count());
}
diff --git a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/EntityTypeAttributeConventionTest.cs b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/EntityTypeAttributeConventionTest.cs
index 30ffcb703f8..a1d1a49d793 100644
--- a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/EntityTypeAttributeConventionTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/EntityTypeAttributeConventionTest.cs
@@ -1,7 +1,8 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// 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.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
using Microsoft.Data.Entity.Metadata.Conventions.Internal;
using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
@@ -21,7 +22,7 @@ public void NotMappedAttribute_overrides_configuration_from_convention_source()
new NotMappedEntityTypeAttributeConvention().Apply(entityBuilder);
- Assert.Equal(0, modelBuilder.Metadata.GetEntityTypes().Count);
+ Assert.Equal(0, modelBuilder.Metadata.GetEntityTypes().Count());
}
[Fact]
@@ -33,7 +34,7 @@ public void NotMappedAttribute_does_not_override_configuration_from_explicit_sou
new NotMappedEntityTypeAttributeConvention().Apply(entityBuilder);
- Assert.Equal(1, modelBuilder.Metadata.GetEntityTypes().Count);
+ Assert.Equal(1, modelBuilder.Metadata.GetEntityTypes().Count());
}
[Fact]
@@ -42,7 +43,7 @@ public void NotMappedAttribute_ignores_entityTypes_with_conventional_builder()
var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet());
modelBuilder.Entity();
- Assert.Equal(1, modelBuilder.Model.GetEntityTypes().Count);
+ Assert.Equal(1, modelBuilder.Model.GetEntityTypes().Count());
}
#endregion
diff --git a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/NavigationAttributeConventionTest.cs b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/NavigationAttributeConventionTest.cs
index 72ca9d223c3..435d0329b1b 100644
--- a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/NavigationAttributeConventionTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/NavigationAttributeConventionTest.cs
@@ -68,8 +68,8 @@ public void NotMappedAttribute_does_not_override_configuration_from_explicit_sou
[Fact]
public void NotMappedAttribute_ignores_navigation_with_conventional_builder()
{
- var model = new Model();
- var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet(), model);
+ var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet());
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.DoesNotContain(model.FindEntityType(typeof(Blog)).GetNavigations(), nav => nav.Name == nameof(Blog.BlogDetails));
@@ -175,8 +175,8 @@ public void RequiredAttribute_does_not_set_is_required_for_navigation_to_depende
[Fact]
public void RequiredAttribute_sets_is_required_with_conventional_builder()
{
- var model = new Model();
- var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet(), model);
+ var modelBuilder = new ModelBuilder(new CoreConventionSetBuilder().CreateConventionSet());
+ var model = (Model)modelBuilder.Model;
modelBuilder.Entity();
Assert.True(model.FindEntityType(typeof(BlogDetails)).GetForeignKeys().Single(fk => fk.PrincipalEntityType?.ClrType == typeof(Blog)).IsRequired);
diff --git a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs
index 3e87d865595..4f4c157d13d 100644
--- a/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/ModelConventions/RelationshipDiscoveryConventionTest.cs
@@ -52,7 +52,7 @@ public void One_to_one_bidirectional_is_discovered()
Assert.Same(entityBuilder, new RelationshipDiscoveryConvention().Apply(entityBuilder));
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), OneToOneDependent.NavigationProperty.Name, unique: true);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -67,7 +67,7 @@ public void One_to_many_unidirectional_is_upgraded_to_one_to_one_bidirectional()
Assert.Same(dependentEntityBuilder, new RelationshipDiscoveryConvention().Apply(dependentEntityBuilder));
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), OneToOnePrincipal.NavigationProperty.Name, unique: true);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -85,7 +85,7 @@ public void Two_one_to_many_unidirectional_are_upgraded_to_one_to_one_bidirectio
Assert.Same(dependentEntityBuilder, new RelationshipDiscoveryConvention().Apply(dependentEntityBuilder));
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), OneToOnePrincipal.NavigationProperty.Name, unique: true);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -100,7 +100,7 @@ public void One_to_many_unidirectional_is_not_upgraded_to_one_to_one_bidirection
Assert.Same(dependentEntityBuilder, new RelationshipDiscoveryConvention().Apply(dependentEntityBuilder));
VerifyRelationship(principalEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -111,7 +111,7 @@ public void One_to_many_unidirectional_is_discovered()
Assert.Same(entityBuilder, new RelationshipDiscoveryConvention().Apply(entityBuilder));
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), null, unique: false);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -125,7 +125,7 @@ public void One_to_many_unidirectional_is_upgraded_to_one_to_many_bidirectional(
Assert.Same(dependentEntityBuilder, new RelationshipDiscoveryConvention().Apply(dependentEntityBuilder));
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), OneToManyPrincipal.NavigationProperty.Name, unique: false);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -140,7 +140,7 @@ public void One_to_many_unidirectional_is_not_upgraded_to_one_to_many_bidirectio
VerifyRelationship(principalEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -151,7 +151,7 @@ public void One_to_many_bidirectional_is_discovered()
Assert.Same(entityBuilder, new RelationshipDiscoveryConvention().Apply(entityBuilder));
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), OneToManyPrincipal.NavigationProperty.Name, unique: false);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -162,7 +162,7 @@ public void Many_to_one_unidirectional_is_discovered()
Assert.Same(entityBuilder, new RelationshipDiscoveryConvention().Apply(entityBuilder));
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), null, unique: false);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -176,7 +176,7 @@ public void Many_to_one_unidirectional_is_upgraded_to_many_to_one_bidirectional(
Assert.Same(principalEntityBuilder, new RelationshipDiscoveryConvention().Apply(principalEntityBuilder));
VerifyRelationship(principalEntityBuilder.Metadata.GetNavigations().Single(), OneToManyDependent.NavigationProperty.Name, unique: false);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -191,7 +191,7 @@ public void Many_to_one_unidirectional_is_not_upgraded_to_many_to_one_bidirectio
VerifyRelationship(principalEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
VerifyRelationship(dependentEntityBuilder.Metadata.GetNavigations().Single(), null, unique: false, singleRelationship: false);
- Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, principalEntityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -202,7 +202,7 @@ public void Many_to_one_bidirectional_is_discovered()
Assert.Same(entityBuilder, new RelationshipDiscoveryConvention().Apply(entityBuilder));
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), OneToManyDependent.NavigationProperty.Name, unique: false);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -215,7 +215,7 @@ public void Many_to_many_bidirectional_is_not_discovered()
Assert.Empty(entityBuilder.Metadata.GetForeignKeys());
Assert.Empty(entityBuilder.Metadata.GetNavigations());
- Assert.Equal(1, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(1, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -227,7 +227,7 @@ public void Ambiguous_navigations_are_not_discovered()
Assert.Empty(entityBuilder.Metadata.GetForeignKeys());
Assert.Empty(entityBuilder.Metadata.GetNavigations());
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -243,7 +243,7 @@ public void Existing_relationship_is_removed_if_ambiguous()
Assert.Empty(entityBuilderFirst.Metadata.GetForeignKeys());
Assert.Empty(entityBuilderFirst.Metadata.GetNavigations());
Assert.Empty(entityBuilderSecond.Metadata.GetNavigations());
- Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -258,7 +258,7 @@ public void Existing_relationship_removes_ambiguity_if_higher_source()
VerifyRelationship(entityBuilderFirst.Metadata.FindNavigation(MultipleNavigationsFirst.CollectionNavigationProperty.Name), null, unique: false, singleRelationship: false);
VerifyRelationship(entityBuilderFirst.Metadata.FindNavigation(MultipleNavigationsFirst.NonCollectionNavigationProperty.Name), nameof(MultipleNavigationsSecond.MultipleNavigationsFirst), unique: true, singleRelationship: false);
- Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -273,7 +273,7 @@ public void Navigations_are_not_discovered_if_ambiguous_inverse()
Assert.Empty(entityBuilderFirst.Metadata.GetForeignKeys());
Assert.Empty(entityBuilderFirst.Metadata.GetNavigations());
Assert.Empty(entityBuilderSecond.Metadata.GetNavigations());
- Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -289,7 +289,7 @@ public void Existing_relationship_is_removed_if_ambiguous_inverse()
Assert.Empty(entityBuilderFirst.Metadata.GetForeignKeys());
Assert.Empty(entityBuilderFirst.Metadata.GetNavigations());
Assert.Empty(entityBuilderSecond.Metadata.GetNavigations());
- Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -304,7 +304,7 @@ public void Existing_relationship_removes_ambiguity_in_inverse_if_higher_source(
VerifyRelationship(entityBuilderFirst.Metadata.FindNavigation(MultipleNavigationsFirst.CollectionNavigationProperty.Name), null, unique: false, singleRelationship: false);
VerifyRelationship(entityBuilderFirst.Metadata.FindNavigation(MultipleNavigationsFirst.NonCollectionNavigationProperty.Name), nameof(MultipleNavigationsSecond.MultipleNavigationsFirst), unique: true, singleRelationship: false);
- Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilderFirst.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -358,7 +358,7 @@ public void Navigations_to_base_and_derived_are_discovered()
Assert.Empty(baseFk.FindNavigationsTo(entityBuilder.Metadata));
Assert.Empty(derivedFk.FindNavigationsTo(entityBuilder.Metadata));
Assert.Equal(2, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -381,7 +381,7 @@ public void Navigations_to_base_and_derived_are_discovered_if_inverse_from_base(
Assert.Equal(nameof(Base.BaseNavigation), baseFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Empty(derivedFk.FindNavigationsTo(entityBuilder.Metadata));
Assert.Equal(2, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -404,7 +404,7 @@ public void Navigations_to_derived_and_base_are_discovered_if_inverse_from_base(
Assert.Equal(nameof(Base.BaseNavigation), baseFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Empty(derivedFk.FindNavigationsTo(entityBuilder.Metadata));
Assert.Equal(2, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -427,7 +427,7 @@ public void Navigations_to_base_and_derived_are_discovered_if_inverse_from_deriv
Assert.Empty(baseFk.FindNavigationsTo(entityBuilder.Metadata));
Assert.Equal(nameof(DerivedOne.DerivedNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(2, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -450,7 +450,7 @@ public void Navigation_pairs_to_base_and_derived_are_discovered()
Assert.Equal(nameof(Base.BaseNavigation), baseFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(nameof(DerivedOne.DerivedNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(3, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(4, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(4, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -466,7 +466,7 @@ public void Navigation_to_base_is_discovered()
VerifyRelationship(entityBuilder.Metadata.FindNavigation(nameof(NavigationsToBaseAndDerived.Base)),
expectedInverseName: nameof(Base.BaseNavigation), unique: true);
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -488,7 +488,7 @@ public void Existing_navigation_to_derived_is_promoted()
VerifyRelationship(entityBuilder.Metadata.FindNavigation(nameof(NavigationsToBaseAndDerived.Base)),
expectedInverseName: nameof(Base.BaseNavigation), unique: true);
Assert.Empty(derivedBuilder.Metadata.GetDeclaredNavigations());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -510,7 +510,7 @@ public void Existing_navigation_from_derived_is_promoted()
VerifyRelationship(baseBuilder.Metadata.FindNavigation(nameof(Base.BaseNavigation)),
expectedInverseName: nameof(NavigationsToBaseAndDerived.Base), unique: true);
Assert.Empty(derivedBuilder.Metadata.GetDeclaredNavigations());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -530,7 +530,7 @@ public void Navigation_from_derived_is_not_discovered_if_ambiguous()
Assert.Empty(entityBuilder.Metadata.GetForeignKeys());
Assert.Empty(derivedBuilder.Metadata.GetNavigations());
Assert.Empty(derivedBuilder.Metadata.GetForeignKeys());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -550,7 +550,7 @@ public void Existing_relationship_to_base_removes_ambiguity()
VerifyRelationship(baseBuilder.Metadata.GetNavigations().Single(), expectedInverseName: null, unique: false, singleRelationship: false);
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), nameof(DerivedOne.DerivedNavigation), unique: true, singleRelationship: false);
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -570,7 +570,7 @@ public void Navigation_to_derived_is_not_discovered_if_inverse_ambiguous()
Assert.Empty(entityBuilder.Metadata.GetForeignKeys());
Assert.Empty(derivedBuilder.Metadata.GetNavigations());
Assert.Empty(derivedBuilder.Metadata.GetForeignKeys());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -590,7 +590,7 @@ public void Existing_relationship_to_base_removes_ambiguity_in_derived_inverse()
VerifyRelationship(baseBuilder.Metadata.GetNavigations().Single(), expectedInverseName: null, unique: false, singleRelationship: false);
VerifyRelationship(entityBuilder.Metadata.GetNavigations().Single(), nameof(DerivedOne.DerivedNavigation), unique: true, singleRelationship: false);
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -611,7 +611,7 @@ public void Navigation_to_derived_is_discovered()
.Single(n => n.Name == nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey;
Assert.Equal(nameof(DerivedOne.DerivedNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -632,7 +632,7 @@ public void Navigation_to_derived_is_discovered_if_inverse_inherited()
.Single(n => n.Name == nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey;
Assert.Equal(nameof(Base.BaseNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -650,7 +650,7 @@ public void Navigation_to_base_is_not_discovered_if_base_ignored()
Assert.Empty(entityBuilder.Metadata.GetForeignKeys());
Assert.Empty(entityBuilder.Metadata.GetNavigations());
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
@@ -668,7 +668,7 @@ public void Navigation_to_derived_is_discovered_if_base_ignored()
var derivedFk = entityBuilder.Metadata.FindNavigation(nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey;
Assert.Equal(nameof(DerivedOne.BaseNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name);
Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count());
- Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count);
+ Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count());
}
[Fact]
diff --git a/test/EntityFramework.Core.Tests/Metadata/NavigationExtensionsTest.cs b/test/EntityFramework.Core.Tests/Metadata/NavigationExtensionsTest.cs
index acc0a3c05c7..fcd3fdb7aef 100644
--- a/test/EntityFramework.Core.Tests/Metadata/NavigationExtensionsTest.cs
+++ b/test/EntityFramework.Core.Tests/Metadata/NavigationExtensionsTest.cs
@@ -1,7 +1,6 @@
// 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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@@ -96,8 +95,8 @@ private static IModel BuildModel(
bool createProducts = true, bool createCategory = true,
bool createFeaturedProductCategory = true, bool createFeaturedProduct = true)
{
- var model = new Model();
- var builder = TestHelpers.Instance.CreateConventionBuilder(model);
+ var builder = TestHelpers.Instance.CreateConventionBuilder();
+ var model = builder.Model;
builder.Entity();
builder.Entity();
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/DataAnnotationsTestBase.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/DataAnnotationsTestBase.cs
index f7ed0e60cd5..bf98f167b31 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/DataAnnotationsTestBase.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/DataAnnotationsTestBase.cs
@@ -4,7 +4,6 @@
using System;
using System.Linq;
using Microsoft.Data.Entity.Internal;
-using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
@@ -18,8 +17,8 @@ public abstract class DataAnnotationsTestBase : ModelBuilderTestBase
[Fact]
public virtual void NotMappedAttribute_removes_ambiguity_in_conventional_relationship_building()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Contains("Details", model.FindEntityType(typeof(Book)).GetNavigations().Select(nav => nav.Name));
@@ -30,8 +29,8 @@ public virtual void NotMappedAttribute_removes_ambiguity_in_conventional_relatio
[Fact]
public virtual void NotMappedAttribute_removes_ambiguity_in_conventional_relationship_building_with_base()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
@@ -54,8 +53,8 @@ public virtual void NotMappedAttribute_removes_ambiguity_in_conventional_relatio
[Fact]
public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_relationalship_building()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Equal("Label",
@@ -67,8 +66,8 @@ public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_r
[Fact]
public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_relationalship_building_with_base()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Same(model.FindEntityType(typeof(BookLabel)), model.FindEntityType(typeof(SpecialBookLabel)).BaseType);
@@ -91,8 +90,8 @@ public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_r
//[Fact]
public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_relationalship_building_with_base_ignored()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasBaseType(null);
modelBuilder.Ignore();
@@ -106,8 +105,8 @@ public virtual void InversePropertyAttribute_removes_ambiguity_in_conventional_r
[Fact]
public virtual void ForeignKeyAttribute_creates_two_relationships_if_applied_on_property_on_both_side()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Null(model.FindEntityType(typeof(Post)).FindNavigation("PostDetails").ForeignKey.PrincipalToDependent);
@@ -120,8 +119,8 @@ public virtual void ForeignKeyAttribute_creates_two_relationships_if_applied_on_
[Fact]
public virtual void ForeignKeyAttribute_creates_two_relationships_if_applied_on_navigations_on_both_side_and_values_do_not_match()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Null(model.FindEntityType(typeof(Post)).FindNavigation("Author").ForeignKey.PrincipalToDependent);
@@ -134,8 +133,8 @@ public virtual void ForeignKeyAttribute_creates_two_relationships_if_applied_on_
[Fact]
public virtual void ForeignKeyAttribute_creates_two_relationships_if_applied_on_navigation_and_property_on_different_side_and_values_do_not_match()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
Assert.Null(model.FindEntityType(typeof(AuthorDetails)).FindNavigation("Author").ForeignKey.PrincipalToDependent);
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/ManyToOneTestBase.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/ManyToOneTestBase.cs
index aaeff198cb1..866102a4496 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/ManyToOneTestBase.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/ManyToOneTestBase.cs
@@ -5,11 +5,9 @@
using System.Linq;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Metadata;
-using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
// ReSharper disable once CheckNamespace
-
namespace Microsoft.Data.Entity.Tests
{
public abstract partial class ModelBuilderTest
@@ -19,8 +17,8 @@ public abstract class ManyToOneTestBase : ModelBuilderTestBase
[Fact]
public virtual void Finds_existing_navigations_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity()
.HasMany(e => e.Orders).WithOne(e => e.Customer)
.HasForeignKey(e => e.CustomerId);
@@ -57,8 +55,8 @@ public virtual void Finds_existing_navigations_and_uses_associated_FK()
[Fact]
public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder
.Entity().HasOne(o => o.Customer).WithMany()
@@ -87,8 +85,8 @@ public virtual void Finds_existing_navigation_to_principal_and_uses_associated_F
[Fact]
public virtual void Finds_existing_navigation_to_dependent_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity()
.HasOne().WithMany(e => e.Orders)
@@ -120,8 +118,8 @@ public virtual void Finds_existing_navigation_to_dependent_and_uses_associated_F
[Fact]
public virtual void Creates_both_navigations_and_does_not_use_existing_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity().HasOne().WithMany().HasForeignKey(e => e.CustomerId);
modelBuilder.Ignore();
@@ -151,8 +149,8 @@ public virtual void Creates_both_navigations_and_does_not_use_existing_FK()
[Fact]
public virtual void Creates_both_navigations_and_creates_new_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -187,8 +185,8 @@ public virtual void Creates_both_navigations_and_creates_new_FK()
[Fact]
public virtual void Creates_relationship_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -219,8 +217,8 @@ public virtual void Creates_relationship_with_navigation_to_principal()
[Fact]
public virtual void Creates_relationship_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -251,8 +249,8 @@ public virtual void Creates_relationship_with_navigation_to_dependent()
[Fact]
public virtual void Creates_relationship_with_no_navigations()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -287,8 +285,8 @@ public virtual void Creates_relationship_with_no_navigations()
[Fact]
public virtual void Creates_both_navigations_and_uses_specified_FK_even_if_found_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -325,8 +323,8 @@ public virtual void Creates_both_navigations_and_uses_specified_FK_even_if_found
[Fact]
public virtual void Creates_both_navigations_with_existing_FK_not_found_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -362,8 +360,8 @@ public virtual void Creates_both_navigations_with_existing_FK_not_found_by_conve
[Fact]
public virtual void Creates_both_navigations_and_creates_FK_specified()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -399,8 +397,8 @@ public virtual void Creates_both_navigations_and_creates_FK_specified()
[Fact]
public virtual void Creates_specified_FK_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -430,8 +428,8 @@ public virtual void Creates_specified_FK_with_navigation_to_principal()
[Fact]
public virtual void Creates_specified_FK_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -463,8 +461,8 @@ public virtual void Creates_specified_FK_with_navigation_to_dependent()
[Fact]
public virtual void Creates_relationship_with_no_navigations_and_specified_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -499,8 +497,8 @@ public virtual void Creates_relationship_with_no_navigations_and_specified_FK()
[Fact]
public virtual void Creates_both_navigations_and_creates_shadow_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -537,8 +535,8 @@ public virtual void Creates_both_navigations_and_creates_shadow_FK()
[Fact]
public virtual void Creates_shadow_FK_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -571,8 +569,8 @@ public virtual void Creates_shadow_FK_with_navigation_to_principal()
[Fact]
public virtual void Creates_shadow_FK_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -605,8 +603,8 @@ public virtual void Creates_shadow_FK_with_navigation_to_dependent()
[Fact]
public virtual void Creates_shadow_FK_with_no_navigations_with()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -642,8 +640,8 @@ public virtual void Creates_shadow_FK_with_no_navigations_with()
[Fact]
public virtual void Creates_both_navigations_and_matches_shadow_FK_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity().Property("BigMakId");
modelBuilder.Ignore();
@@ -677,8 +675,8 @@ public virtual void Creates_both_navigations_and_matches_shadow_FK_by_convention
[Fact]
public virtual void Creates_both_navigations_and_overrides_existing_FK_if_uniqueness_does_not_match()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder
.Entity().HasOne(e => e.BigMak).WithOne()
.HasForeignKey(c => c.BurgerId);
@@ -712,8 +710,8 @@ public virtual void Creates_both_navigations_and_overrides_existing_FK_if_unique
[Fact]
public virtual void Can_use_explicitly_specified_PK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -752,8 +750,8 @@ public virtual void Can_use_explicitly_specified_PK()
[Fact]
public virtual void Can_use_non_PK_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -801,8 +799,8 @@ public virtual void Can_use_non_PK_principal()
[Fact]
public virtual void Can_have_both_convention_properties_specified()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -842,8 +840,8 @@ public virtual void Can_have_both_convention_properties_specified()
[Fact]
public virtual void Can_have_both_convention_properties_specified_in_any_order()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -883,8 +881,8 @@ public virtual void Can_have_both_convention_properties_specified_in_any_order()
[Fact]
public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_key()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -930,8 +928,8 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_
[Fact]
public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_key_in_any_order()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -977,8 +975,8 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_
[Fact]
public virtual void Can_have_principal_key_by_convention_specified_with_explicit_PK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1022,8 +1020,8 @@ public virtual void Can_have_principal_key_by_convention_specified_with_explicit
[Fact]
public virtual void Can_have_principal_key_by_convention_specified_with_explicit_PK_in_any_order()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1067,8 +1065,8 @@ public virtual void Can_have_principal_key_by_convention_specified_with_explicit
[Fact]
public virtual void Creates_both_navigations_and_finds_existing_composite_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(c => new { c.Id1, c.Id2 });
modelBuilder
.Entity().HasOne(e => e.Whoopper).WithMany()
@@ -1105,8 +1103,8 @@ public virtual void Creates_both_navigations_and_finds_existing_composite_FK()
[Fact]
public virtual void Creates_both_navigations_and_creates_composite_FK_specified()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(c => new { c.Id1, c.Id2 });
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1145,8 +1143,8 @@ public virtual void Creates_both_navigations_and_creates_composite_FK_specified(
[Fact]
public virtual void Can_use_alternate_composite_key()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b => b.HasKey(c => new { c.Id1, c.Id2 }));
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1195,8 +1193,8 @@ public virtual void Can_use_alternate_composite_key()
[Fact]
public virtual void Can_use_alternate_composite_key_in_any_order()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b => b.HasKey(c => new { c.Id1, c.Id2 }));
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1245,8 +1243,8 @@ public virtual void Can_use_alternate_composite_key_in_any_order()
[Fact]
public virtual void Creates_specified_composite_FK_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(c => new { c.Id1, c.Id2 });
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1281,8 +1279,8 @@ public virtual void Creates_specified_composite_FK_with_navigation_to_principal(
[Fact]
public virtual void Creates_specified_composite_FK_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(c => new { c.Id1, c.Id2 });
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1317,8 +1315,8 @@ public virtual void Creates_specified_composite_FK_with_navigation_to_dependent(
[Fact]
public virtual void Creates_relationship_with_no_navigations_and_specified_composite_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(c => new { c.Id1, c.Id2 });
modelBuilder.Entity().HasMany(w => w.Tomatoes).WithOne(t => t.Whoopper);
modelBuilder.Entity();
@@ -1389,8 +1387,8 @@ public virtual void Finds_and_removes_existing_one_to_one_relationship()
[Fact]
public virtual void Can_add_annotations()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -1532,8 +1530,8 @@ public virtual void Can_change_delete_behavior()
[Fact]
public virtual void Can_set_foreign_key_property_when_matching_property_added()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
var foreignKey = model.FindEntityType(typeof(DependentEntity)).GetForeignKeys().Single();
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderGenericTest.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderGenericTest.cs
index 64f9e2ad32c..c7afcc467c2 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderGenericTest.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderGenericTest.cs
@@ -12,28 +12,11 @@
using Xunit;
// ReSharper disable once CheckNamespace
+
namespace Microsoft.Data.Entity.Tests
{
public class ModelBuilderGenericTest : ModelBuilderTest
{
- [Fact]
- public void Can_create_a_model_builder_with_given_conventions_and_model()
- {
- var convention = new TestConvention();
- var conventions = new ConventionSet();
- conventions.EntityTypeAddedConventions.Add(convention);
-
- var model = new Model();
- var modelBuilder = new ModelBuilder(conventions, model);
-
- Assert.Same(model, modelBuilder.Model);
-
- modelBuilder.Entity();
-
- Assert.True(convention.Applied);
- Assert.NotNull(model.FindEntityType(typeof(Random)));
- }
-
[Fact]
public void Can_create_a_model_builder_with_given_conventions_only()
{
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericStringTest.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericStringTest.cs
index eaa6124dfc6..97b260f8b78 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericStringTest.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericStringTest.cs
@@ -5,9 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
-using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Metadata.Builders;
-using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
// ReSharper disable once CheckNamespace
@@ -20,8 +18,8 @@ public class NonGenericOneToManyType : OneToManyTestBase
[Fact]
public override void Can_set_foreign_key_property_when_matching_property_added()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
var foreignKey = model.FindEntityType(typeof(DependentEntity)).GetForeignKeys().Single();
@@ -42,8 +40,8 @@ public class NonGenericManyToOneType : ManyToOneTestBase
[Fact]
public override void Can_set_foreign_key_property_when_matching_property_added()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
var foreignKey = model.FindEntityType(typeof(DependentEntity)).GetForeignKeys().Single();
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericTest.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericTest.cs
index acab2da52c8..d3dc91e3bb2 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericTest.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderNonGenericTest.cs
@@ -8,7 +8,6 @@
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Metadata.Builders;
-using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
// ReSharper disable once CheckNamespace
@@ -21,8 +20,8 @@ public class NonGenericNonRelationship : NonRelationshipTestBase
[Fact]
public void Can_set_model_annotation()
{
- var model = new Model();
- var modelBuilder = (NonGenericTestModelBuilder)CreateModelBuilder(model);
+ var modelBuilder = (NonGenericTestModelBuilder)CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder = modelBuilder.HasAnnotation("Fus", "Ro");
@@ -38,8 +37,8 @@ public class NonGenericOneToMany : OneToManyTestBase
[Fact]
public override void Can_set_foreign_key_property_when_matching_property_added()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
var foreignKey = model.FindEntityType(typeof(DependentEntity)).GetForeignKeys().Single();
@@ -60,8 +59,8 @@ public class NonGenericManyToOne : ManyToOneTestBase
[Fact]
public override void Can_set_foreign_key_property_when_matching_property_added()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
var foreignKey = model.FindEntityType(typeof(DependentEntity)).GetForeignKeys().Single();
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderTestBase.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderTestBase.cs
index f1898a840a7..8c97ceda1f8 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderTestBase.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/ModelBuilderTestBase.cs
@@ -7,10 +7,10 @@
using Microsoft.Data.Entity.FunctionalTests.TestUtilities;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Metadata.Builders;
-using Microsoft.Data.Entity.Metadata.Internal;
using Xunit;
// ReSharper disable once CheckNamespace
+
namespace Microsoft.Data.Entity.Tests
{
public abstract partial class ModelBuilderTest
@@ -89,14 +89,12 @@ protected void AssertEqual(
indexComparer);
}
- protected TestModelBuilder CreateModelBuilder() => CreateModelBuilder(new Model());
-
- protected virtual TestModelBuilder CreateModelBuilder(Model model)
- => CreateTestModelBuilder(TestHelpers.Instance.CreateConventionBuilder(model));
+ protected virtual TestModelBuilder CreateModelBuilder()
+ => CreateTestModelBuilder(TestHelpers.Instance.CreateConventionBuilder());
protected TestModelBuilder HobNobBuilder()
{
- var builder = CreateModelBuilder(new Model());
+ var builder = CreateModelBuilder();
builder.Entity().HasKey(e => new { e.Id1, e.Id2 });
builder.Entity().HasKey(e => new { e.Id1, e.Id2 });
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/NonRelationshipTestBase.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/NonRelationshipTestBase.cs
index c90cd49043b..0957894f7ba 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/NonRelationshipTestBase.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/NonRelationshipTestBase.cs
@@ -3,7 +3,6 @@
using System;
using System.Linq;
-using System.Reflection;
using Microsoft.Data.Entity.Internal;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Metadata.Internal;
@@ -19,8 +18,8 @@ public abstract class NonRelationshipTestBase : ModelBuilderTestBase
[Fact]
public virtual void Can_get_entity_builder_for_clr_type()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityBuilder = modelBuilder.Entity();
@@ -31,8 +30,8 @@ public virtual void Can_get_entity_builder_for_clr_type()
[Fact]
public virtual void Can_set_entity_key_from_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasKey(b => b.Id);
@@ -45,8 +44,8 @@ public virtual void Can_set_entity_key_from_clr_property()
[Fact]
public virtual void Can_set_entity_key_from_property_name_when_no_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -82,8 +81,8 @@ public virtual void Can_set_entity_key_from_clr_property_when_property_ignored()
[Fact]
public virtual void Can_set_composite_entity_key_from_clr_properties()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder
.Entity()
@@ -99,8 +98,8 @@ public virtual void Can_set_composite_entity_key_from_clr_properties()
[Fact]
public virtual void Can_set_composite_entity_key_from_property_names_when_mixed_properties()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Ignore();
modelBuilder.Ignore();
@@ -120,8 +119,8 @@ public virtual void Can_set_composite_entity_key_from_property_names_when_mixed_
[Fact]
public virtual void Can_set_entity_key_with_annotations()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var keyBuilder = modelBuilder
.Entity()
@@ -151,7 +150,7 @@ public virtual void Can_upgrade_candidate_key_to_primary_key()
Assert.Same(key, entity.GetKeys().Single());
Assert.Equal(Customer.NameProperty.Name, entity.FindPrimaryKey().Properties.Single().Name);
- var idProperty = (IProperty)EntityTypeExtensions.FindProperty((IEntityType)entity, Customer.IdProperty);
+ var idProperty = (IProperty)entity.FindProperty(Customer.IdProperty);
Assert.False(idProperty.RequiresValueGenerator);
Assert.Equal(ValueGenerated.Never, idProperty.ValueGenerated);
}
@@ -159,8 +158,8 @@ public virtual void Can_upgrade_candidate_key_to_primary_key()
[Fact]
public virtual void Can_set_alternate_key_from_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasAlternateKey(b => b.AlternateKey);
@@ -173,8 +172,8 @@ public virtual void Can_set_alternate_key_from_clr_property()
[Fact]
public virtual void Can_set_alternate_key_from_property_name_when_no_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -231,8 +230,8 @@ public virtual void Can_set_property_annotation()
[Fact]
public virtual void Can_set_property_annotation_when_no_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var propertyBuilder = modelBuilder
.Entity()
@@ -244,7 +243,7 @@ public virtual void Can_set_property_annotation_when_no_clr_property()
[Fact]
public virtual void Can_add_multiple_properties()
{
- var modelBuilder = CreateModelBuilder(new Model());
+ var modelBuilder = CreateModelBuilder();
modelBuilder.Ignore();
modelBuilder.Entity(b =>
@@ -260,8 +259,8 @@ public virtual void Can_add_multiple_properties()
[Fact]
public virtual void Properties_are_required_by_default_only_if_CLR_type_is_nullable()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -286,8 +285,8 @@ public virtual void Properties_are_required_by_default_only_if_CLR_type_is_nulla
[Fact]
public virtual void Properties_can_be_ignored()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityType = (IEntityType)modelBuilder.Entity().Metadata;
@@ -310,8 +309,8 @@ public virtual void Properties_can_be_ignored()
[Fact]
public virtual void Can_ignore_a_property_that_is_part_of_explicit_entity_key_throws()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityBuilder = modelBuilder.Entity();
entityBuilder.HasKey(e => e.Id);
@@ -323,8 +322,8 @@ public virtual void Can_ignore_a_property_that_is_part_of_explicit_entity_key_th
[Fact]
public virtual void Ignoring_shadow_properties_when_they_have_been_added_explicitly_throws()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityBuilder = modelBuilder.Entity();
entityBuilder.Property("Shadow");
@@ -350,8 +349,8 @@ public virtual void Can_add_shadow_properties_when_they_have_been_ignored()
[Fact]
public virtual void Ignoring_a_navigation_property_removes_discovered_entity_types()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
b.Ignore(c => c.Details);
@@ -360,14 +359,14 @@ public virtual void Ignoring_a_navigation_property_removes_discovered_entity_typ
modelBuilder.Validate();
- Assert.Equal(1, model.GetEntityTypes().Count);
+ Assert.Equal(1, model.GetEntityTypes().Count());
}
[Fact]
public virtual void Ignoring_a_navigation_property_removes_discovered_relationship()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
b.Ignore(c => c.Details);
@@ -377,16 +376,16 @@ public virtual void Ignoring_a_navigation_property_removes_discovered_relationsh
modelBuilder.Validate();
- Assert.Equal(0, model.GetEntityTypes()[0].GetForeignKeys().Count());
- Assert.Equal(0, model.GetEntityTypes()[1].GetForeignKeys().Count());
- Assert.Equal(2, model.GetEntityTypes().Count);
+ Assert.Equal(0, model.GetEntityTypes().First().GetForeignKeys().Count());
+ Assert.Equal(0, model.GetEntityTypes().Last().GetForeignKeys().Count());
+ Assert.Equal(2, model.GetEntityTypes().Count());
}
[Fact]
public virtual void Properties_can_be_made_required()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -411,8 +410,8 @@ public virtual void Properties_can_be_made_required()
[Fact]
public virtual void Properties_can_be_made_optional()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -431,8 +430,8 @@ public virtual void Properties_can_be_made_optional()
[Fact]
public virtual void Non_nullable_properties_cannot_be_made_optional()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -459,8 +458,8 @@ public virtual void Non_nullable_properties_cannot_be_made_optional()
[Fact]
public virtual void Properties_specified_by_string_are_shadow_properties_unless_already_known_to_be_CLR_properties()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -488,8 +487,8 @@ public virtual void Properties_specified_by_string_are_shadow_properties_unless_
[Fact]
public virtual void Properties_can_be_made_concurency_tokens()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -523,8 +522,8 @@ public virtual void Properties_can_be_made_concurency_tokens()
[Fact]
public virtual void Properties_can_be_set_to_generate_values_on_Add()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -551,8 +550,8 @@ public virtual void Properties_can_be_set_to_generate_values_on_Add()
[Fact]
public virtual void Properties_can_be_set_to_be_store_computed()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -579,8 +578,8 @@ public virtual void Properties_can_be_set_to_be_store_computed()
[Fact]
public virtual void Can_set_max_length_for_properties()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity(b =>
{
@@ -622,8 +621,8 @@ public virtual void PropertyBuilder_methods_can_be_chained()
[Fact]
public virtual void Can_add_index()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder
.Entity()
@@ -638,8 +637,8 @@ public virtual void Can_add_index()
[Fact]
public virtual void Can_add_index_when_no_clr_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder
.Entity(b =>
@@ -657,8 +656,8 @@ public virtual void Can_add_index_when_no_clr_property()
[Fact]
public virtual void Can_add_multiple_indexes()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityBuilder = modelBuilder.Entity();
var firstIndexBuilder = entityBuilder.HasIndex(ix => ix.Id).IsUnique();
@@ -675,8 +674,8 @@ public virtual void Can_add_multiple_indexes()
[Fact]
public virtual void Can_set_primary_key_by_convention_for_user_specified_shadow_property()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
var entityBuilder = modelBuilder.Entity();
@@ -687,7 +686,7 @@ public virtual void Can_set_primary_key_by_convention_for_user_specified_shadow_
entityBuilder.Property("Id");
Assert.NotNull(entityType.FindPrimaryKey());
- AssertEqual(new [] { "Id" }, entityType.FindPrimaryKey().Properties.Select(p => p.Name));
+ AssertEqual(new[] { "Id" }, entityType.FindPrimaryKey().Properties.Select(p => p.Name));
}
}
}
diff --git a/test/EntityFramework.Core.Tests/ModelBuilderTest/OneToManyTestBase.cs b/test/EntityFramework.Core.Tests/ModelBuilderTest/OneToManyTestBase.cs
index 8e8f02f1f06..1126a639527 100644
--- a/test/EntityFramework.Core.Tests/ModelBuilderTest/OneToManyTestBase.cs
+++ b/test/EntityFramework.Core.Tests/ModelBuilderTest/OneToManyTestBase.cs
@@ -11,7 +11,6 @@
using Xunit;
// ReSharper disable once CheckNamespace
-
namespace Microsoft.Data.Entity.Tests
{
public abstract partial class ModelBuilderTest
@@ -21,8 +20,8 @@ public abstract class OneToManyTestBase : ModelBuilderTestBase
[Fact]
public virtual void Finds_existing_navigations_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity()
.HasOne(o => o.Customer).WithMany(c => c.Orders)
@@ -59,8 +58,8 @@ public virtual void Finds_existing_navigations_and_uses_associated_FK()
[Fact]
public virtual void Finds_existing_navigation_to_principal_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder
.Entity().HasOne(c => c.Customer).WithMany()
@@ -89,8 +88,8 @@ public virtual void Finds_existing_navigation_to_principal_and_uses_associated_F
[Fact]
public virtual void Finds_existing_navigation_to_dependent_and_uses_associated_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity().HasMany(e => e.Orders).WithOne()
.HasForeignKey(e => e.CustomerId);
modelBuilder.Entity();
@@ -120,8 +119,8 @@ public virtual void Finds_existing_navigation_to_dependent_and_uses_associated_F
[Fact]
public virtual void Creates_both_navigations_and_uses_existing_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder
.Entity().HasOne(e => e.Customer).WithMany(e => e.Orders)
@@ -155,8 +154,8 @@ public virtual void Creates_both_navigations_and_uses_existing_FK()
[Fact]
public virtual void Creates_relationship_with_both_navigations()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -191,8 +190,8 @@ public virtual void Creates_relationship_with_both_navigations()
[Fact]
public virtual void Creates_relationship_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -222,8 +221,8 @@ public virtual void Creates_relationship_with_navigation_to_dependent()
[Fact]
public virtual void Creates_relationship_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -251,8 +250,8 @@ public virtual void Creates_relationship_with_navigation_to_principal()
[Fact]
public virtual void Creates_relationship_with_no_navigations()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -288,8 +287,8 @@ public virtual void Creates_relationship_with_no_navigations()
[Fact]
public virtual void Creates_both_navigations_and_uses_specified_FK_even_if_found_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -326,8 +325,8 @@ public virtual void Creates_both_navigations_and_uses_specified_FK_even_if_found
[Fact]
public virtual void Creates_both_navigations_and_uses_existing_FK_not_found_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder
.Entity().HasOne(e => e.BigMak).WithMany()
@@ -363,8 +362,8 @@ public virtual void Creates_both_navigations_and_uses_existing_FK_not_found_by_c
[Fact]
public virtual void Creates_both_navigations_and_creates_FK_specified()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -400,8 +399,8 @@ public virtual void Creates_both_navigations_and_creates_FK_specified()
[Fact]
public virtual void Creates_specified_FK_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -432,8 +431,8 @@ public virtual void Creates_specified_FK_with_navigation_to_dependent()
[Fact]
public virtual void Creates_specified_FK_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -462,8 +461,8 @@ public virtual void Creates_specified_FK_with_navigation_to_principal()
[Fact]
public virtual void Creates_relationship_with_no_navigations_and_specified_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -498,8 +497,8 @@ public virtual void Creates_relationship_with_no_navigations_and_specified_FK()
[Fact]
public virtual void Creates_both_navigations_and_creates_shadow_FK()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -536,8 +535,8 @@ public virtual void Creates_both_navigations_and_creates_shadow_FK()
[Fact]
public virtual void Creates_shadow_FK_with_navigation_to_dependent()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -569,8 +568,8 @@ public virtual void Creates_shadow_FK_with_navigation_to_dependent()
[Fact]
public virtual void Creates_shadow_FK_with_navigation_to_principal()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -603,8 +602,8 @@ public virtual void Creates_shadow_FK_with_navigation_to_principal()
[Fact]
public virtual void Creates_shadow_FK_with_no_navigation()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity();
modelBuilder.Entity();
modelBuilder.Ignore();
@@ -641,8 +640,8 @@ public virtual void Creates_shadow_FK_with_no_navigation()
[Fact]
public virtual void Creates_both_navigations_and_matches_shadow_FK_property_by_convention()
{
- var model = new Model();
- var modelBuilder = CreateModelBuilder(model);
+ var modelBuilder = CreateModelBuilder();
+ var model = modelBuilder.Model;
modelBuilder.Entity