/// <summary> /// Creates two navigation properties representing an association between two entity types. /// </summary> /// <param name="propertyInfo">Information to create the navigation property.</param> /// <param name="partnerInfo">Information to create the partner navigation property.</param> /// <returns>Created navigation property.</returns> public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name"); EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target"); EdmUtil.CheckArgumentNull(partnerInfo, "partnerInfo"); EdmUtil.CheckArgumentNull(partnerInfo.Name, "partnerInfo.Name"); EdmUtil.CheckArgumentNull(partnerInfo.Target, "partnerInfo.Target"); EdmNavigationProperty end1 = new EdmNavigationProperty( partnerInfo.Target, propertyInfo.Name, CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"), propertyInfo.DependentProperties, propertyInfo.ContainsTarget, propertyInfo.OnDelete); EdmNavigationProperty end2 = new EdmNavigationProperty( propertyInfo.Target, partnerInfo.Name, CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"), partnerInfo.DependentProperties, partnerInfo.ContainsTarget, partnerInfo.OnDelete); end1.partner = end2; end2.partner = end1; return(end1); }
public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull <EdmNavigationPropertyInfo>(propertyInfo, "propertyInfo"); EdmNavigationProperty edmNavigationProperty = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo)); base.AddProperty(edmNavigationProperty); return(edmNavigationProperty); }
public EdmNavigationPropertyInfo Clone() { EdmNavigationPropertyInfo edmNavigationPropertyInfo = new EdmNavigationPropertyInfo(); edmNavigationPropertyInfo.Name = this.Name; edmNavigationPropertyInfo.Target = this.Target; edmNavigationPropertyInfo.TargetMultiplicity = this.TargetMultiplicity; edmNavigationPropertyInfo.DependentProperties = this.DependentProperties; edmNavigationPropertyInfo.ContainsTarget = this.ContainsTarget; edmNavigationPropertyInfo.OnDelete = this.OnDelete; return edmNavigationPropertyInfo; }
public EdmNavigationPropertyInfo Clone() { EdmNavigationPropertyInfo edmNavigationPropertyInfo = new EdmNavigationPropertyInfo(); edmNavigationPropertyInfo.Name = this.Name; edmNavigationPropertyInfo.Target = this.Target; edmNavigationPropertyInfo.TargetMultiplicity = this.TargetMultiplicity; edmNavigationPropertyInfo.DependentProperties = this.DependentProperties; edmNavigationPropertyInfo.ContainsTarget = this.ContainsTarget; edmNavigationPropertyInfo.OnDelete = this.OnDelete; return(edmNavigationPropertyInfo); }
private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmNavigationPropertyInfo edmNavigationPropertyInfo = null; if (partnerInfo == null) { EdmNavigationPropertyInfo edmNavigationPropertyInfo1 = new EdmNavigationPropertyInfo(); edmNavigationPropertyInfo = edmNavigationPropertyInfo1; partnerInfo = edmNavigationPropertyInfo1; } if (partnerInfo.Name == null) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } EdmNavigationPropertyInfo edmNavigationPropertyInfo2 = edmNavigationPropertyInfo; string name = propertyInfo.Name; string empty = name; if (name == null) { empty = string.Empty; } edmNavigationPropertyInfo2.Name = string.Concat(empty, "Partner"); } if (partnerInfo.Target == null) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } edmNavigationPropertyInfo.Target = this; } if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } edmNavigationPropertyInfo.TargetMultiplicity = EdmMultiplicity.ZeroOrOne; } EdmNavigationPropertyInfo edmNavigationPropertyInfo3 = edmNavigationPropertyInfo; EdmNavigationPropertyInfo edmNavigationPropertyInfo4 = edmNavigationPropertyInfo3; if (edmNavigationPropertyInfo3 == null) { edmNavigationPropertyInfo4 = partnerInfo; } return(edmNavigationPropertyInfo4); }
public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull <EdmNavigationPropertyInfo>(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull <string>(propertyInfo.Name, "propertyInfo.Name"); EdmUtil.CheckArgumentNull <IEdmEntityType>(propertyInfo.Target, "propertyInfo.Target"); EdmUtil.CheckArgumentNull <EdmNavigationPropertyInfo>(partnerInfo, "partnerInfo"); EdmUtil.CheckArgumentNull <string>(partnerInfo.Name, "partnerInfo.Name"); EdmUtil.CheckArgumentNull <IEdmEntityType>(partnerInfo.Target, "partnerInfo.Target"); EdmNavigationProperty edmNavigationProperty = new EdmNavigationProperty(partnerInfo.Target, propertyInfo.Name, EdmNavigationProperty.CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"), propertyInfo.DependentProperties, propertyInfo.ContainsTarget, propertyInfo.OnDelete); EdmNavigationProperty edmNavigationProperty1 = new EdmNavigationProperty(propertyInfo.Target, partnerInfo.Name, EdmNavigationProperty.CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"), partnerInfo.DependentProperties, partnerInfo.ContainsTarget, partnerInfo.OnDelete); edmNavigationProperty.partner = edmNavigationProperty1; edmNavigationProperty1.partner = edmNavigationProperty; return(edmNavigationProperty); }
public EdmNavigationProperty AddBidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull<EdmNavigationPropertyInfo>(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull<IEdmEntityType>(propertyInfo.Target, "propertyInfo.Target"); EdmEntityType target = propertyInfo.Target as EdmEntityType; if (target != null) { EdmNavigationProperty edmNavigationProperty = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo)); base.AddProperty(edmNavigationProperty); target.AddProperty(edmNavigationProperty.Partner); return edmNavigationProperty; } else { throw new ArgumentException("propertyInfo.Target", Strings.Constructable_TargetMustBeStock(typeof(EdmEntityType).FullName)); } }
/// <summary> /// Creates and adds a navigation property to this type and adds its navigation partner to the navigation target type. /// </summary> /// <param name="propertyInfo">Information to create the navigation property.</param> /// <param name="partnerInfo">Information to create the partner navigation property.</param> /// <returns>Created navigation property.</returns> public EdmNavigationProperty AddBidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target"); EdmEntityType targetType = propertyInfo.Target as EdmEntityType; if (targetType == null) { throw new ArgumentException("propertyInfo.Target", Strings.Constructable_TargetMustBeStock(typeof(EdmEntityType).FullName)); } EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo)); this.AddProperty(property); targetType.AddProperty(property.Partner); return property; }
/// <summary> /// The puspose of this method is to make sure that some of the <paramref name="partnerInfo"/> fields are set to valid partner defaults. /// For example if <paramref name="partnerInfo"/>.Target is null, it will be set to this entity type. If <paramref name="partnerInfo"/>.TargetMultiplicity /// is unknown, it will be set to 0..1, etc. /// Whenever this method applies new values to <paramref name="partnerInfo"/>, it will return a copy of it (thus won't modify the original). /// If <paramref name="partnerInfo"/> is null, a new info object will be produced. /// </summary> /// <param name="propertyInfo">Primary navigation property info.</param> /// <param name="partnerInfo">Partner navigation property info. May be null.</param> /// <returns>Partner info.</returns> private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmNavigationPropertyInfo partnerInfoOverride = null; if (partnerInfo == null) { partnerInfo = partnerInfoOverride = new EdmNavigationPropertyInfo(); } if (partnerInfo.Name == null) { if (partnerInfoOverride == null) { partnerInfoOverride = partnerInfo.Clone(); } partnerInfoOverride.Name = (propertyInfo.Name ?? String.Empty) + "Partner"; } if (partnerInfo.Target == null) { if (partnerInfoOverride == null) { partnerInfoOverride = partnerInfo.Clone(); } partnerInfoOverride.Target = this; } if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown) { if (partnerInfoOverride == null) { partnerInfoOverride = partnerInfo.Clone(); } partnerInfoOverride.TargetMultiplicity = EdmMultiplicity.ZeroOrOne; } return partnerInfoOverride ?? partnerInfo; }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable<string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode); } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties, Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.Partner != null ? property.Partner.Multiplicity() : property.Type.TypeKind() == EdmTypeKind.Collection ? EdmMultiplicity.Many : property.Type.TypeKind() == EdmTypeKind.Entity ? EdmMultiplicity.ZeroOrOne : EdmMultiplicity.Unknown, }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
private void CreateNavigationProperty(EntityTypeConfiguration config) { Contract.Assert(config != null); EdmEntityType entityType = (EdmEntityType)(_types[config.ClrType]); foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties) { EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo(); info.Name = navProp.Name; info.TargetMultiplicity = navProp.Multiplicity; info.Target = _types[navProp.RelatedClrType] as IEdmEntityType; info.OnDelete = navProp.OnDeleteAction; if (navProp.ReferentialConstraint.Any()) { info.DependentProperties = ReorderDependentProperties(navProp); } //TODO: If target end has a multiplity of 1 this assumes the source end is 0..1. // I think a better default multiplicity is * entityType.AddUnidirectionalNavigation(info); } }
private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmNavigationPropertyInfo edmNavigationPropertyInfo = null; if (partnerInfo == null) { EdmNavigationPropertyInfo edmNavigationPropertyInfo1 = new EdmNavigationPropertyInfo(); edmNavigationPropertyInfo = edmNavigationPropertyInfo1; partnerInfo = edmNavigationPropertyInfo1; } if (partnerInfo.Name == null) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } EdmNavigationPropertyInfo edmNavigationPropertyInfo2 = edmNavigationPropertyInfo; string name = propertyInfo.Name; string empty = name; if (name == null) { empty = string.Empty; } edmNavigationPropertyInfo2.Name = string.Concat(empty, "Partner"); } if (partnerInfo.Target == null) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } edmNavigationPropertyInfo.Target = this; } if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown) { if (edmNavigationPropertyInfo == null) { edmNavigationPropertyInfo = partnerInfo.Clone(); } edmNavigationPropertyInfo.TargetMultiplicity = EdmMultiplicity.ZeroOrOne; } EdmNavigationPropertyInfo edmNavigationPropertyInfo3 = edmNavigationPropertyInfo; EdmNavigationPropertyInfo edmNavigationPropertyInfo4 = edmNavigationPropertyInfo3; if (edmNavigationPropertyInfo3 == null) { edmNavigationPropertyInfo4 = partnerInfo; } return edmNavigationPropertyInfo4; }
/// <summary> /// Creates and adds a unidirectional navigation property to this type. /// Default partner property is created, but not added to the navigation target type. /// </summary> /// <param name="propertyInfo">Information to create the navigation property.</param> /// <returns>Created navigation property.</returns> public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo) { return AddUnidirectionalNavigation(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, null)); }
/// <summary> /// Creates two navigation properties representing an association between two entity types. /// </summary> /// <param name="propertyInfo">Information to create the navigation property.</param> /// <param name="partnerInfo">Information to create the partner navigation property.</param> /// <returns>Created navigation property.</returns> public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name"); EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target"); EdmUtil.CheckArgumentNull(partnerInfo, "partnerInfo"); EdmUtil.CheckArgumentNull(partnerInfo.Name, "partnerInfo.Name"); EdmUtil.CheckArgumentNull(partnerInfo.Target, "partnerInfo.Target"); EdmNavigationProperty end1 = new EdmNavigationProperty( partnerInfo.Target, propertyInfo.Name, CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"), propertyInfo.DependentProperties, propertyInfo.ContainsTarget, propertyInfo.OnDelete); EdmNavigationProperty end2 = new EdmNavigationProperty( propertyInfo.Target, partnerInfo.Name, CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"), partnerInfo.DependentProperties, partnerInfo.ContainsTarget, partnerInfo.OnDelete); end1.partner = end2; end2.partner = end1; return end1; }
/// <summary> /// Creates and adds a unidirectional navigation property to this type. /// Navigation property partner is created, but not added to the navigation target type. /// </summary> /// <param name="propertyInfo">Information to create the navigation property.</param> /// <param name="partnerInfo">Information to create the partner navigation property.</param> /// <returns>Created navigation property.</returns> public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo"); EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo)); this.AddProperty(property); return property; }
private void CreateEntityTypeBody(EdmEntityType type, IEntityTypeConfiguration config) { CreateStructuralTypeBody(type, config); IEdmStructuralProperty[] keys = config.Keys.Select(p => type.DeclaredProperties.OfType<IEdmStructuralProperty>().First(dp => dp.Name == p.PropertyInfo.Name)).ToArray(); type.AddKeys(keys); foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties) { EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo(); info.Name = navProp.Name; info.TargetMultiplicity = navProp.Multiplicity; info.Target = _types[navProp.RelatedClrType] as IEdmEntityType; //TODO: If target end has a multiplity of 1 this assumes the source end is 0..1. // I think a better default multiplicity is * type.AddUnidirectionalNavigation(info); } }
public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo) { EdmUtil.CheckArgumentNull<EdmNavigationPropertyInfo>(propertyInfo, "propertyInfo"); EdmUtil.CheckArgumentNull<string>(propertyInfo.Name, "propertyInfo.Name"); EdmUtil.CheckArgumentNull<IEdmEntityType>(propertyInfo.Target, "propertyInfo.Target"); EdmUtil.CheckArgumentNull<EdmNavigationPropertyInfo>(partnerInfo, "partnerInfo"); EdmUtil.CheckArgumentNull<string>(partnerInfo.Name, "partnerInfo.Name"); EdmUtil.CheckArgumentNull<IEdmEntityType>(partnerInfo.Target, "partnerInfo.Target"); EdmNavigationProperty edmNavigationProperty = new EdmNavigationProperty(partnerInfo.Target, propertyInfo.Name, EdmNavigationProperty.CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"), propertyInfo.DependentProperties, propertyInfo.ContainsTarget, propertyInfo.OnDelete); EdmNavigationProperty edmNavigationProperty1 = new EdmNavigationProperty(propertyInfo.Target, partnerInfo.Name, EdmNavigationProperty.CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"), partnerInfo.DependentProperties, partnerInfo.ContainsTarget, partnerInfo.OnDelete); edmNavigationProperty.partner = edmNavigationProperty1; edmNavigationProperty1.partner = edmNavigationProperty; return edmNavigationProperty; }