1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
//---------------------------------------------------------------------
// <copyright file="ReferentialConstraint.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
namespace System.Data.Metadata.Edm
{
/// <summary>
/// This class describes referential constraint on the relationships
/// </summary>
public sealed class ReferentialConstraint : MetadataItem
{
#region Constructors
/// <summary>
/// Constructs a new constraint on the relationship
/// </summary>
/// <param name="fromRole">role from which the relationship originates</param>
/// <param name="toRole">role to which the relationship is linked/targeted to</param>
/// <param name="toProperties">properties on entity type of from role which take part in the constraint</param>
/// <param name="fromProperties">properties on entity type of to role which take part in the constraint</param>
/// <exception cref="ArgumentNullException">Argument Null exception if any of the arguments is null</exception>
internal ReferentialConstraint(RelationshipEndMember fromRole,
RelationshipEndMember toRole,
IEnumerable<EdmProperty> fromProperties,
IEnumerable<EdmProperty> toProperties)
{
_fromRole = EntityUtil.GenericCheckArgumentNull(fromRole, "fromRole");
_toRole = EntityUtil.GenericCheckArgumentNull(toRole, "toRole");
_fromProperties = new ReadOnlyMetadataCollection<EdmProperty>(new MetadataCollection<EdmProperty>(
EntityUtil.GenericCheckArgumentNull(fromProperties, "fromProperties")));
_toProperties = new ReadOnlyMetadataCollection<EdmProperty>(new MetadataCollection<EdmProperty>(
EntityUtil.GenericCheckArgumentNull(toProperties, "toProperties")));
}
#endregion
#region Fields
private RelationshipEndMember _fromRole;
private RelationshipEndMember _toRole;
private readonly ReadOnlyMetadataCollection<EdmProperty> _fromProperties;
private readonly ReadOnlyMetadataCollection<EdmProperty> _toProperties;
#endregion
#region Properties
/// <summary>
/// Returns the kind of the type
/// </summary>
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.ReferentialConstraint; } }
/// <summary>
/// Returns the identity for this constraint
/// </summary>
internal override string Identity
{
get
{
return this.FromRole.Name + "_" + this.ToRole.Name;
}
}
/// <summary>
/// Returns the FromRole which takes part in this referential constraint
/// </summary>
/// <exception cref="System.ArgumentNullException">Thrown if value passed into setter is null</exception>
/// <exception cref="System.InvalidOperationException">Thrown if the ReferentialConstraint instance is in ReadOnly state</exception>
[MetadataProperty(BuiltInTypeKind.RelationshipEndMember, false)]
public RelationshipEndMember FromRole
{
get
{
return _fromRole;
}
}
/// <summary>
/// Returns the ToRole which takes part in this referential constraint
/// </summary>
/// <exception cref="System.ArgumentNullException">Thrown if value passed into setter is null</exception>
/// <exception cref="System.InvalidOperationException">Thrown if the ReferentialConstraint instance is in ReadOnly state</exception>
[MetadataProperty(BuiltInTypeKind.RelationshipEndMember, false)]
public RelationshipEndMember ToRole
{
get
{
return _toRole;
}
}
/// <summary>
/// Returns the collection of properties on the from role on which the constraint is defined on
/// </summary>
[MetadataProperty(BuiltInTypeKind.EdmProperty, true)]
public ReadOnlyMetadataCollection<EdmProperty> FromProperties
{
get
{
return _fromProperties;
}
}
/// <summary>
/// Returns the collection of properties on the ToRole on whose value the constraint is defined on
/// </summary>
[MetadataProperty(BuiltInTypeKind.EdmProperty, true)]
public ReadOnlyMetadataCollection<EdmProperty> ToProperties
{
get
{
return _toProperties;
}
}
#endregion
#region Methods
/// <summary>
/// Overriding System.Object.ToString to provide better String representation
/// for this type.
/// </summary>
public override string ToString()
{
return this.FromRole.Name + "_" + this.ToRole.Name;
}
/// <summary>
/// Sets this item to be read-only, once this is set, the item will never be writable again.
/// </summary>
internal override void SetReadOnly()
{
if (!IsReadOnly)
{
base.SetReadOnly();
RelationshipEndMember fromRole = FromRole;
if (fromRole != null)
{
fromRole.SetReadOnly();
}
RelationshipEndMember toRole = ToRole;
if (toRole != null)
{
toRole.SetReadOnly();
}
this.FromProperties.Source.SetReadOnly();
this.ToProperties.Source.SetReadOnly();
}
}
#endregion
}
}
|