Permalink
Browse files

TheOldNewMetadata

Removal of Code First metadata (part 1: CSDL)

- Removal of all System.Data.Entity.Edm CSDL classes except EdmModel and EdmNamespace which have no analogs in core metadata.
- Updated CSDL validator and serializers to enable an incremental approach to this refactoring (and because they are generally useful anyway)
- Added unit tests for the changes in core metadata.
  • Loading branch information...
1 parent cb15f2e commit d9dfc66d201dcfce6fcda8b2c915689f5de5b11f @anpete anpete committed Oct 4, 2012
Showing 306 changed files with 8,691 additions and 9,586 deletions.
View
@@ -21,3 +21,4 @@ EntityFramework.SqlServerCompact.xml
*.REMOTE.*
*.LOCAL.*
StyleCop.Cache
+*.csproj.DotSettings
@@ -749,8 +749,7 @@ internal static ConcurrencyMode GetConcurrencyMode(TypeUsage typeUsage)
{
Facet concurrencyFacet;
if (typeUsage.Facets.TryGetValue(EdmProviderManifest.ConcurrencyModeFacetName, false, out concurrencyFacet)
- &&
- concurrencyFacet.Value != null)
+ && concurrencyFacet.Value != null)
{
var concurrencyMode = (ConcurrencyMode)concurrencyFacet.Value;
return concurrencyMode;
@@ -25,6 +25,12 @@ public sealed class AssociationEndMember : RelationshipEndMember
{
}
+ internal AssociationEndMember(string name, EntityType entityType)
+ : base(name, new RefType(entityType), default(RelationshipMultiplicity))
+ {
+ // testing only
+ }
+
/// <summary>
/// Returns the kind of the type
/// </summary>
@@ -2,6 +2,9 @@
namespace System.Data.Entity.Core.Metadata.Edm
{
+ using System.Diagnostics.Contracts;
+ using System.Linq;
+
/// <summary>
/// Class for representing an Association set
/// </summary>
@@ -17,8 +20,8 @@ internal AssociationSet(string name, AssociationType associationType)
{
}
- private readonly ReadOnlyMetadataCollection<AssociationSetEnd> _associationSetEnds =
- new ReadOnlyMetadataCollection<AssociationSetEnd>(new MetadataCollection<AssociationSetEnd>());
+ private readonly ReadOnlyMetadataCollection<AssociationSetEnd> _associationSetEnds
+ = new ReadOnlyMetadataCollection<AssociationSetEnd>(new MetadataCollection<AssociationSetEnd>());
/// <summary>
/// Returns the association type associated with this association set
@@ -37,6 +40,65 @@ public ReadOnlyMetadataCollection<AssociationSetEnd> AssociationSetEnds
get { return _associationSetEnds; }
}
+ internal EntitySet SourceSet
+ {
+ get
+ {
+ var associationSetEnd = AssociationSetEnds.FirstOrDefault();
+
+ return (associationSetEnd != null)
+ ? associationSetEnd.EntitySet
+ : null;
+ }
+ set
+ {
+ Contract.Requires(value != null);
+ Util.ThrowIfReadOnly(this);
+ Contract.Assert(ElementType.SourceEnd != null);
+
+ var associationSetEnd = new AssociationSetEnd(value, this, ElementType.SourceEnd);
+
+ if (AssociationSetEnds.Count == 0)
+ {
+ AddAssociationSetEnd(associationSetEnd);
+ }
+ else
+ {
+ AssociationSetEnds.Source[0] = associationSetEnd;
+ }
+ }
+ }
+
+ internal EntitySet TargetSet
+ {
+ get
+ {
+ var associationSetEnd = AssociationSetEnds.ElementAtOrDefault(1);
+
+ return (associationSetEnd != null)
+ ? associationSetEnd.EntitySet
+ : null;
+ }
+ set
+ {
+ Contract.Requires(value != null);
+ Util.ThrowIfReadOnly(this);
+ Contract.Assert(AssociationSetEnds.Any());
+ Contract.Assert(ElementType.TargetEnd != null);
+
+ var associationSetEnd = new AssociationSetEnd(value, this, ElementType.TargetEnd);
+
+ if (AssociationSetEnds.Count == 1)
+ {
+ AddAssociationSetEnd(associationSetEnd);
+ }
+ else
+ {
+ AssociationSetEnds.Source[1] = associationSetEnd;
+ }
+ }
+ }
+
/// <summary>
/// Returns the kind of the type
/// </summary>
@@ -4,6 +4,8 @@ namespace System.Data.Entity.Core.Metadata.Edm
{
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+ using System.Diagnostics.Contracts;
+ using System.Linq;
using System.Threading;
/// <summary>
@@ -12,6 +14,12 @@ namespace System.Data.Entity.Core.Metadata.Edm
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance")]
public sealed class AssociationType : RelationshipType
{
+ internal AssociationType()
+ : this("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
+ {
+ // testing only
+ }
+
/// <summary>
/// Initializes a new instance of Association Type with the given name, namespace, version and ends
/// </summary>
@@ -27,7 +35,10 @@ public sealed class AssociationType : RelationshipType
DataSpace dataSpace)
: base(name, namespaceName, dataSpace)
{
- _referentialConstraints = new ReadOnlyMetadataCollection<ReferentialConstraint>(new MetadataCollection<ReferentialConstraint>());
+ _referentialConstraints
+ = new ReadOnlyMetadataCollection<ReferentialConstraint>(
+ new MetadataCollection<ReferentialConstraint>());
+
_isForeignKey = foreignKey;
}
@@ -64,6 +75,64 @@ public ReadOnlyMetadataCollection<AssociationEndMember> AssociationEndMembers
}
}
+ internal ReferentialConstraint Constraint
+ {
+ get { return ReferentialConstraints.SingleOrDefault(); }
+ set
+ {
+ Contract.Requires(value != null);
+ Util.ThrowIfReadOnly(this);
+
+ var constraint = Constraint;
+
+ if (constraint != null)
+ {
+ ReferentialConstraints.Source.Remove(constraint);
+ }
+
+ AddReferentialConstraint(value);
+ }
+ }
+
+ internal AssociationEndMember SourceEnd
+ {
+ get { return KeyMembers.FirstOrDefault() as AssociationEndMember; }
+ set
+ {
+ Contract.Requires(value != null);
+ Util.ThrowIfReadOnly(this);
+
+ if (KeyMembers.Count == 0)
+ {
+ AddKeyMember(value);
+ }
+ else
+ {
+ KeyMembers.Source[0] = value;
+ }
+ }
+ }
+
+ internal AssociationEndMember TargetEnd
+ {
+ get { return KeyMembers.ElementAtOrDefault(1) as AssociationEndMember; }
+ set
+ {
+ Contract.Requires(value != null);
+ Util.ThrowIfReadOnly(this);
+ Contract.Assert(KeyMembers.Any());
+
+ if (KeyMembers.Count == 1)
+ {
+ AddKeyMember(value);
+ }
+ else
+ {
+ KeyMembers.Source[1] = value;
+ }
+ }
+ }
+
/// <summary>
/// Returns the list of constraints for this association type
/// </summary>
Oops, something went wrong.

0 comments on commit d9dfc66

Please sign in to comment.