private Boolean NumberOfRecordsMatchesMultiplicity(int RecordCnt, RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.ZeroOrOne: // zero is ignored because a foreignKey != null is assumed. case RelationshipMultiplicity.One: { if (RecordCnt == 1) { return(true); } break; } case RelationshipMultiplicity.Many: { return(true); } default: { throw new ArgumentException("Switch Error."); } } return(false); }
/// <summary> /// Determine if the specified member is compatible with lazy loading. /// </summary> /// <param name="ospaceEntityType"> /// OSpace EntityType representing a type that may be proxied. /// </param> /// <param name="member"> /// Member of the <paramref name="ospaceEntityType" /> to be examined. /// </param> /// <returns> /// True if the member is compatible with lazy loading; otherwise false. /// </returns> /// <remarks> /// To be compatible with lazy loading, /// a member must meet the criteria for being able to be proxied (defined elsewhere), /// and must be a navigation property. /// In addition, for relationships with a multiplicity of Many, /// the property type must be an implementation of ICollection<T>. /// </remarks> internal static bool IsLazyLoadCandidate(EntityType ospaceEntityType, EdmMember member) { Debug.Assert(ospaceEntityType.DataSpace == DataSpace.OSpace, "ospaceEntityType.DataSpace must be OSpace"); bool isCandidate = false; if (member.BuiltInTypeKind == BuiltInTypeKind.NavigationProperty) { NavigationProperty navProperty = (NavigationProperty)member; RelationshipMultiplicity multiplicity = navProperty.ToEndMember.RelationshipMultiplicity; PropertyInfo propertyInfo = EntityUtil.GetTopProperty(ospaceEntityType.ClrType, member.Name); Debug.Assert(propertyInfo != null, "Should have found lazy loading property"); Type propertyValueType = propertyInfo.PropertyType; if (multiplicity == RelationshipMultiplicity.Many) { Type elementType; isCandidate = EntityUtil.TryGetICollectionElementType(propertyValueType, out elementType); } else if (multiplicity == RelationshipMultiplicity.One || multiplicity == RelationshipMultiplicity.ZeroOrOne) { // This is an EntityReference property. isCandidate = true; } } return(isCandidate); }
public TestModelBuilder Association( string name, string sourceEntity, RelationshipMultiplicity sourceEndKind, string sourceNavigationProperty, string targetEntity, RelationshipMultiplicity targetEndKind, string targetNavigationProperty) { var sourceEntityType = _model.GetEntityType(sourceEntity); var targetEntityType = _model.GetEntityType(targetEntity); var association = _model.AddAssociationType(name, sourceEntityType, sourceEndKind, targetEntityType, targetEndKind); _model.AddAssociationSet(name + "Set", association); if (sourceNavigationProperty != null) { sourceEntityType.AddNavigationProperty(sourceNavigationProperty, association); } if (targetNavigationProperty != null) { targetEntityType.AddNavigationProperty(targetNavigationProperty, association); } return(this); }
public static AssociationType AddAssociationType( this EdmModel model, string name, EntityType sourceEntityType, RelationshipMultiplicity sourceAssociationEndKind, EntityType targetEntityType, RelationshipMultiplicity targetAssociationEndKind, string modelNamespace = null) { DebugCheck.NotNull(model); DebugCheck.NotEmpty(name); DebugCheck.NotNull(sourceEntityType); DebugCheck.NotNull(targetEntityType); var associationType = new AssociationType( name, modelNamespace ?? DefaultModelNamespace, false, DataSpace.CSpace) { SourceEnd = new AssociationEndMember( name + "_Source", sourceEntityType.GetReferenceType(), sourceAssociationEndKind), TargetEnd = new AssociationEndMember( name + "_Target", targetEntityType.GetReferenceType(), targetAssociationEndKind) }; model.AddAssociationType(associationType); return(associationType); }
private void LoadRelationshipTypes() { foreach (EdmRelationshipAttribute customAttribute in this.SourceAssembly.GetCustomAttributes <EdmRelationshipAttribute>()) { if (!this.TryFindNullParametersInRelationshipAttribute(customAttribute)) { bool flag = false; if (customAttribute.Role1Name == customAttribute.Role2Name) { this.SessionData.EdmItemErrors.Add(new EdmItemError(Strings.SameRoleNameOnRelationshipAttribute((object)customAttribute.RelationshipName, (object)customAttribute.Role2Name))); flag = true; } if (!flag) { AssociationType associationType = new AssociationType(customAttribute.RelationshipName, customAttribute.RelationshipNamespaceName, customAttribute.IsForeignKey, DataSpace.OSpace); this.SessionData.TypesInLoading.Add(associationType.FullName, (EdmType)associationType); this.TrackClosure(customAttribute.Role1Type); this.TrackClosure(customAttribute.Role2Type); string r1Name = customAttribute.Role1Name; Type r1Type = customAttribute.Role1Type; RelationshipMultiplicity r1Multiplicity = customAttribute.Role1Multiplicity; this.AddTypeResolver((Action)(() => this.ResolveAssociationEnd(associationType, r1Name, r1Type, r1Multiplicity))); string r2Name = customAttribute.Role2Name; Type r2Type = customAttribute.Role2Type; RelationshipMultiplicity r2Multiplicity = customAttribute.Role2Multiplicity; this.AddTypeResolver((Action)(() => this.ResolveAssociationEnd(associationType, r2Name, r2Type, r2Multiplicity))); this.CacheEntry.TypesInAssembly.Add((EdmType)associationType); } } } }
// <summary> // Initializes a new instance of AssociationEndMember // </summary> // <param name="name"> name of the association end member </param> // <param name="endRefType"> Ref type that this end refers to </param> // <param name="multiplicity"> multiplicity of the end </param> internal AssociationEndMember( string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, endRefType, multiplicity) { }
/// <summary> /// Initializes a new instance of AssociationEndMember /// </summary> /// <param name="name">name of the association end member</param> /// <param name="endRefType">Ref type that this end refers to </param> /// <param name="multiplicity">multiplicity of the end</param> internal AssociationEndMember( string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, endRefType, multiplicity) { }
private static void VerifyMultiplicityCompatibility(RelationshipMultiplicity multiplicity, PropertyInfo propertyInfo) { var isCompatible = true; switch (multiplicity) { case RelationshipMultiplicity.Many: isCompatible = propertyInfo.PropertyType.IsCollection(); break; case RelationshipMultiplicity.One: case RelationshipMultiplicity.ZeroOrOne: isCompatible = !propertyInfo.PropertyType.IsCollection(); break; default: throw new InvalidOperationException(Strings.LightweightNavigationPropertyConfiguration_InvalidMultiplicity(multiplicity)); } if (!isCompatible) { throw new InvalidOperationException( Strings.LightweightNavigationPropertyConfiguration_IncompatibleMultiplicity( RelationshipMultiplicityConverter.MultiplicityToString(multiplicity), propertyInfo.DeclaringType + "." + propertyInfo.Name, propertyInfo.PropertyType)); } }
public AssociationSetEndDetails( AssociationSetEnd associationSetEnd, RelationshipMultiplicity multiplicity, OperationAction deleteBehavior) { AssociationSetEnd = associationSetEnd; Multiplicity = multiplicity; DeleteBehavior = deleteBehavior; }
internal static int?GetUpperBoundOfMultiplicity(RelationshipMultiplicity multiplicity) { if (multiplicity == RelationshipMultiplicity.One || multiplicity == RelationshipMultiplicity.ZeroOrOne) { return(new int?(1)); } return(new int?()); }
/// <summary> /// Initializes a new instance of RelationshipEndMember /// </summary> /// <param name="name">name of the relationship end member</param> /// <param name="endRefType">Ref type that this end refers to </param> /// <param name="multiplicity">The multiplicity of this relationship end</param> /// <exception cref="System.ArgumentNullException">Thrown if name or endRefType arguments is null</exception> /// <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal RelationshipEndMember(string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, TypeUsage.Create(endRefType, new FacetValues{ Nullable = false })) { _relationshipMultiplicity = multiplicity; _deleteBehavior = OperationAction.None; }
/// <summary> /// Initializes a new instance of RelationshipEndMember /// </summary> /// <param name="name">name of the relationship end member</param> /// <param name="endRefType">Ref type that this end refers to </param> /// <param name="multiplicity">The multiplicity of this relationship end</param> /// <exception cref="System.ArgumentNullException">Thrown if name or endRefType arguments is null</exception> /// <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal RelationshipEndMember(string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, TypeUsage.Create(endRefType, new FacetValues { Nullable = false })) { _relationshipMultiplicity = multiplicity; _deleteBehavior = OperationAction.None; }
private CodeExpression GetMultiplicityCodeExpression(RelationshipMultiplicity multiplicity) { // example: // [System.Data.Objects.DataClasses.EdmRelationshipRoleAttribute("CustomerOrder", "Customer", global::System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Customer))] string roleMultiplicity = multiplicity.ToString(); CodeExpression roleMultiplicityExpression = Emitter.EmitEnumMemberExpression( TypeReference.AdoFrameworkMetadataEdmType("RelationshipMultiplicity"), roleMultiplicity); return roleMultiplicityExpression; }
public virtual ConventionNavigationPropertyConfiguration HasRelationshipMultiplicity( RelationshipMultiplicity multiplicity) { if (this._configuration != null && !this._configuration.RelationshipMultiplicity.HasValue) { ConventionNavigationPropertyConfiguration.VerifyMultiplicityCompatibility(multiplicity, this._configuration.NavigationProperty); this._configuration.RelationshipMultiplicity = new RelationshipMultiplicity?(multiplicity); } return(this); }
private CodeExpression GetMultiplicityCodeExpression(RelationshipMultiplicity multiplicity) { // example: // [System.Data.Objects.DataClasses.EdmRelationshipRoleAttribute("CustomerOrder", "Customer", global::System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(Customer))] string roleMultiplicity = multiplicity.ToString(); CodeExpression roleMultiplicityExpression = Emitter.EmitEnumMemberExpression( TypeReference.AdoFrameworkMetadataEdmType("RelationshipMultiplicity"), roleMultiplicity); return(roleMultiplicityExpression); }
public static EntityKey Create(ObjectStateEntry entry) { string entityName = entry.Entity.GetType().Name; var relationships = entry.RelationshipManager .GetAllRelatedEnds() .Select(r => r.RelationshipSet.ElementType) .ToList(); List <string> inboundEdges = new List <string>(); foreach (var relationship in relationships) { var relationshipEnds = relationship.Name.Split('_'); string leftTypeName = relationshipEnds[0]; string rightTypeName = relationshipEnds[1]; RelationshipMultiplicity leftMultiplicity = relationship.RelationshipEndMembers[0].RelationshipMultiplicity; RelationshipMultiplicity rightMultiplicity = relationship.RelationshipEndMembers[1].RelationshipMultiplicity; string theirTypeName; RelationshipMultiplicity ourMultiplicity; RelationshipMultiplicity theirMultiplicity; if (entityName == rightTypeName) { theirTypeName = leftTypeName; ourMultiplicity = rightMultiplicity; theirMultiplicity = leftMultiplicity; } else { theirTypeName = rightTypeName; ourMultiplicity = leftMultiplicity; theirMultiplicity = rightMultiplicity; } bool isManyToMany = ourMultiplicity == RelationshipMultiplicity.Many && theirMultiplicity == RelationshipMultiplicity.Many; bool isOptionalToOptional = ourMultiplicity == RelationshipMultiplicity.ZeroOrOne && theirMultiplicity == RelationshipMultiplicity.ZeroOrOne; bool isSkippable = isManyToMany || isOptionalToOptional; if (!isSkippable) { bool dependantOnUs = (ourMultiplicity == RelationshipMultiplicity.One || ourMultiplicity == RelationshipMultiplicity.ZeroOrOne) && (theirMultiplicity == RelationshipMultiplicity.Many) || (ourMultiplicity == RelationshipMultiplicity.One && theirMultiplicity == RelationshipMultiplicity.ZeroOrOne); if (dependantOnUs) { inboundEdges.Add(theirTypeName); } } } var entityKey = new EntityKey(entityName, inboundEdges); return(entityKey); }
internal static int?GetUpperBoundOfMultiplicity(RelationshipMultiplicity multiplicity) { if (multiplicity == RelationshipMultiplicity.One || multiplicity == RelationshipMultiplicity.ZeroOrOne) { return(1); } else { return(null); } }
internal RelationshipEndMember( string name, RefType endRefType, RelationshipMultiplicity multiplicity) : base(name, TypeUsage.Create((EdmType)endRefType, new FacetValues() { Nullable = (FacetValueContainer <bool?>) new bool?(false) })) { this._relationshipMultiplicity = multiplicity; this._deleteBehavior = OperationAction.None; }
private void GetFromAssociationSetEnd(AssociationSet definingSet, AssociationSet multiplicitySet, out AssociationSetEnd associationSetEnd, out RelationshipMultiplicity multiplicity, out OperationAction deleteBehavior) { // for a situation like this (CD is CascadeDelete) // // -------- CD -------- CD -------- // | A |1 <- 1| AtoB |* <- 1| B | // | |-------| |-------| | // | | | | | | // -------- -------- -------- // // You get // -------- CD -------- // | A |* <- 1| B | // | |-------| | // | | | | // -------- -------- // // Notice that the of the new "link table association" muliplicities are opposite of what comming into the original link table // this seems counter intuitive at first, but makes sense when you think all the way through it // // CascadeDelete Behavior (we can assume the runtime will always delete cascade // to the link table from the outside tables (it actually doesn't, but that is a associationSetEnd = GetAssociationSetEnd(definingSet, true); AssociationSetEnd multiplicityAssociationSetEnd = GetAssociationSetEnd(multiplicitySet, false); multiplicity = multiplicityAssociationSetEnd.CorrespondingAssociationEndMember.RelationshipMultiplicity; deleteBehavior = OperationAction.None; if (multiplicity != RelationshipMultiplicity.Many) { OperationAction otherEndBehavior = GetAssociationSetEnd(definingSet, false).CorrespondingAssociationEndMember.DeleteBehavior; if(otherEndBehavior == OperationAction.None) { // Since the other end does not have an operation // that means that only one end could possibly have an operation, that is good // so set it the operation deleteBehavior = multiplicityAssociationSetEnd.CorrespondingAssociationEndMember.DeleteBehavior; } } }
internal static int GetLowerBoundOfMultiplicity(RelationshipMultiplicity multiplicity) { if (multiplicity == RelationshipMultiplicity.Many || multiplicity == RelationshipMultiplicity.ZeroOrOne) { return(0); } else { return(1); } }
public TestModelBuilder Association( string sourceEntity, RelationshipMultiplicity sourceEndKind, string targetEntity, RelationshipMultiplicity targetEndKind) { _model.AddAssociationSet( "AssociationSet" + _counter++, _model.AddAssociationType( "Association", _model.GetEntityType(sourceEntity), sourceEndKind, _model.GetEntityType(targetEntity), targetEndKind)); return this; }
private void ResolveAssociationEnd( AssociationType associationType, string roleName, Type clrType, RelationshipMultiplicity multiplicity) { EntityType entityType; if (!TryGetRelationshipEndEntityType(clrType, out entityType)) { SessionData.EdmItemErrors.Add( new EdmItemError(Strings.RoleTypeInEdmRelationshipAttributeIsInvalidType(associationType.Name, roleName, clrType))); return; } associationType.AddKeyMember(new AssociationEndMember(roleName, entityType.GetReferenceType(), multiplicity)); }
public virtual ConventionNavigationPropertyConfiguration HasInverseEndMultiplicity( RelationshipMultiplicity multiplicity) { if (this._configuration != null && !this._configuration.InverseEndKind.HasValue) { if (this._configuration.InverseNavigationProperty != (PropertyInfo)null) { ConventionNavigationPropertyConfiguration.VerifyMultiplicityCompatibility(multiplicity, this._configuration.InverseNavigationProperty); } this._configuration.InverseEndKind = new RelationshipMultiplicity?(multiplicity); } return(this); }
public TestModelBuilder Association( string sourceEntity, RelationshipMultiplicity sourceEndKind, string targetEntity, RelationshipMultiplicity targetEndKind) { _model.AddAssociationSet( "AssociationSet" + _counter++, _model.AddAssociationType( "Association", _model.GetEntityType(sourceEntity), sourceEndKind, _model.GetEntityType(targetEntity), targetEndKind)); return(this); }
public NavigationPropertyBuilder ToRole( EntityType entityType, RelationshipMultiplicity relationshipMultiplicity, OperationAction deleteAction = OperationAction.None) { this.toEntityType = entityType; this.toAssociationEndMember = this.builder .WithEntityType(entityType) .RelationshipMultiplicity(relationshipMultiplicity) .DeleteAction(deleteAction) .Build(); return(this); }
/// <summary> /// This method loads all the relationship type that this entity takes part in /// </summary> /// <param name="entityType"></param> /// <param name="context"></param> private void LoadRelationshipTypes() { foreach (EdmRelationshipAttribute roleAttribute in SourceAssembly.GetCustomAttributes(typeof(EdmRelationshipAttribute), false /*inherit*/)) { // Check if there is an entry already with this name if (TryFindNullParametersInRelationshipAttribute(roleAttribute)) { // don't give more errors for these same bad parameters continue; } bool errorEncountered = false; // return error if the role names are the same if (roleAttribute.Role1Name == roleAttribute.Role2Name) { SessionData.EdmItemErrors.Add(new EdmItemError(System.Data.Entity.Strings.SameRoleNameOnRelationshipAttribute(roleAttribute.RelationshipName, roleAttribute.Role2Name), null)); errorEncountered = true; } if (!errorEncountered) { AssociationType associationType = new AssociationType(roleAttribute.RelationshipName, roleAttribute.RelationshipNamespaceName, roleAttribute.IsForeignKey, DataSpace.OSpace); SessionData.TypesInLoading.Add(associationType.FullName, associationType); TrackClosure(roleAttribute.Role1Type); TrackClosure(roleAttribute.Role2Type); // prevent lifting of loop vars string r1Name = roleAttribute.Role1Name; Type r1Type = roleAttribute.Role1Type; RelationshipMultiplicity r1Multiplicity = roleAttribute.Role1Multiplicity; AddTypeResolver(() => ResolveAssociationEnd(associationType, r1Name, r1Type, r1Multiplicity)); // prevent lifting of loop vars string r2Name = roleAttribute.Role2Name; Type r2Type = roleAttribute.Role2Type; RelationshipMultiplicity r2Multiplicity = roleAttribute.Role2Multiplicity; AddTypeResolver(() => ResolveAssociationEnd(associationType, r2Name, r2Type, r2Multiplicity)); // get assembly entry and add association type to the list of types in the assembly Debug.Assert(!CacheEntry.ContainsType(associationType.FullName), "Relationship type must not be present in the list of types"); CacheEntry.TypesInAssembly.Add(associationType); } } }
internal static string MultiplicityToString(RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.Many: return "*"; case RelationshipMultiplicity.One: return "1"; case RelationshipMultiplicity.ZeroOrOne: return "0..1"; default: Debug.Fail("Did you add a new RelationshipMultiplicity?"); return String.Empty; } }
private void ResolveAssociationEnd( AssociationType associationType, string roleName, Type clrType, RelationshipMultiplicity multiplicity) { EntityType entityType; if (!this.TryGetRelationshipEndEntityType(clrType, out entityType)) { this.SessionData.EdmItemErrors.Add(new EdmItemError(Strings.RoleTypeInEdmRelationshipAttributeIsInvalidType((object)associationType.Name, (object)roleName, (object)clrType))); } else { associationType.AddKeyMember((EdmMember) new AssociationEndMember(roleName, entityType.GetReferenceType(), multiplicity)); } }
internal static string TranslateMultiplicity(RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); case RelationshipMultiplicity.Many: return("*"); default: return(string.Empty); } }
public static string ToDisplayString(this RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); case RelationshipMultiplicity.Many: return("*"); default: return("non défini"); } }
/// <summary> /// Calculate how EF's RelationshipMultiplicity is written as EDMX attribute value /// </summary> /// <param name="m"></param> /// <returns></returns> public static string ToXmlValue(this RelationshipMultiplicity m) { switch (m) { case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); case RelationshipMultiplicity.Many: return("*"); default: throw new ArgumentOutOfRangeException("m"); } }
private string GetXmlMultiplicity(RelationshipMultiplicity relationshipMultiplicity) { switch (relationshipMultiplicity) { case RelationshipMultiplicity.Many: return("*"); case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); default: Debug.Fail("Did you add a new RelationshipMultiplicity?"); return(string.Empty); } }
internal static string MultiplicityToString(RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.Many: return("*"); case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); default: Debug.Fail("Did you add a new RelationshipMultiplicity?"); return(String.Empty); } }
private static NavigationPropertyMultiplicity GetMultiplicity(RelationshipMultiplicity relationshipMultiplicity) { switch (relationshipMultiplicity) { case RelationshipMultiplicity.ZeroOrOne: return(NavigationPropertyMultiplicity.ZeroOrOne); case RelationshipMultiplicity.One: return(NavigationPropertyMultiplicity.One); case RelationshipMultiplicity.Many: return(NavigationPropertyMultiplicity.Many); default: throw new NotSupportedException("This should not happen"); } }
// <summary> // Gets a <see cref="RelationshipMultiplicity"/> from a string // </summary> // <param name="value"> string containing multiplicity definition </param> // <param name="multiplicity"> multiplicity value (-1 if there were errors) </param> // <returns> <c>true</c> if the string was parsable, <c>false</c> otherwise </returns> internal static bool TryParseMultiplicity(string value, out RelationshipMultiplicity multiplicity) { switch (value) { case "*": multiplicity = RelationshipMultiplicity.Many; return true; case "1": multiplicity = RelationshipMultiplicity.One; return true; case "0..1": multiplicity = RelationshipMultiplicity.ZeroOrOne; return true; default: multiplicity = (RelationshipMultiplicity)(-1); return false; } }
private static string GetXmlMultiplicity(RelationshipMultiplicity endKind) { switch (endKind) { case RelationshipMultiplicity.Many: return("*"); case RelationshipMultiplicity.One: return("1"); case RelationshipMultiplicity.ZeroOrOne: return("0..1"); default: Debug.Fail("Did you add a new EdmAssociationEndKind?"); return(string.Empty); } }
private static EdmMultiplicity GetEdmMultiplicity( RelationshipMultiplicity relMultiplicity) { switch (relMultiplicity) { case RelationshipMultiplicity.Many: return(EdmMultiplicity.Many); case RelationshipMultiplicity.One: return(EdmMultiplicity.One); case RelationshipMultiplicity.ZeroOrOne: return(EdmMultiplicity.ZeroOrOne); default: return(EdmMultiplicity.Unknown); } }
/// <summary> /// Attribute containing the details for a relationship /// This should match the C-Space relationship information, but having it available in this /// attribute allows us access to this information even in O-Space when there is no context. /// There can be multiple attributes of this type in an assembly. /// </summary> public EdmRelationshipAttribute(string relationshipNamespaceName, string relationshipName, string role1Name, RelationshipMultiplicity role1Multiplicity, Type role1Type, string role2Name, RelationshipMultiplicity role2Multiplicity, Type role2Type) { _relationshipNamespaceName = relationshipNamespaceName; _relationshipName = relationshipName; _role1Name = role1Name; _role1Multiplicity = role1Multiplicity; _role1Type = role1Type; _role2Name = role2Name; _role2Multiplicity = role2Multiplicity; _role2Type = role2Type; }
/// <summary> /// Creates a read-only AssociationEndMember instance. /// </summary> /// <param name="name">The name of the association end member.</param> /// <param name="endRefType">The reference type for the end.</param> /// <param name="multiplicity">The multiplicity of the end.</param> /// <param name="deleteAction">Flag that indicates the delete behavior of the end.</param> /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param> /// <returns>The newly created AssociationEndMember instance.</returns> /// <exception cref="ArgumentException">The specified name is null or empty.</exception> /// <exception cref="ArgumentNullException">The specified reference type is null.</exception> public static AssociationEndMember Create( string name, RefType endRefType, RelationshipMultiplicity multiplicity, OperationAction deleteAction, IEnumerable<MetadataProperty> metadataProperties) { Check.NotEmpty(name, "name"); Check.NotNull(endRefType, "endRefType"); var instance = new AssociationEndMember(name, endRefType, multiplicity); instance.DeleteBehavior = deleteAction; if (metadataProperties != null) { instance.AddMetadataProperties(metadataProperties.ToList()); } instance.SetReadOnly(); return instance; }
/// <summary> /// Attribute containing the details for a relationship /// This should match the C-Space relationship information, but having it available in this /// attribute allows us access to this information even in O-Space when there is no context. /// There can be multiple attributes of this type in an assembly. /// </summary> public EdmRelationshipAttribute(string relationshipNamespaceName, string relationshipName, string role1Name, RelationshipMultiplicity role1Multiplicity, Type role1Type, string role2Name, RelationshipMultiplicity role2Multiplicity, Type role2Type, bool isForeignKey) { _relationshipNamespaceName = relationshipNamespaceName; _relationshipName = relationshipName; _role1Name = role1Name; _role1Multiplicity = role1Multiplicity; _role1Type = role1Type; _role2Name = role2Name; _role2Multiplicity = role2Multiplicity; _role2Type = role2Type; _isForeignKey = isForeignKey; }
public void GetStoreAssociationSetEnd(int index, out AssociationSetEnd storeAssociationSetEnd, out RelationshipMultiplicity multiplicity, out OperationAction deleteBehavior) { Debug.Assert(index >= 0 && index < AssociationSets.Count, "out of bounds dude!!"); Debug.Assert(AssociationSets.Count == 2, "This code depends on only having exactly two AssociationSets"); GetFromAssociationSetEnd(AssociationSets[index], AssociationSets[(index+1)%2], out storeAssociationSetEnd, out multiplicity, out deleteBehavior); }
private AssociationEndMember CreateAssociationEndMember(LoadMethodSessionState session, AssociationEndMember storeEndMember, UniqueIdentifierService usedEndMemberNames, RelationshipMultiplicity multiplicityOverride, OperationAction deleteBehaviorOverride) { Debug.Assert(storeEndMember.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType, "The type is not a ref type"); Debug.Assert(((RefType)storeEndMember.TypeUsage.EdmType).ElementType.BuiltInTypeKind == BuiltInTypeKind.EntityType, "the ref is not holding on to an EntityType"); EntityType storeEntityType = ((EntityType)((RefType)storeEndMember.TypeUsage.EdmType).ElementType); EntityType modelEntityType = session.MappingLookups.StoreEntityTypeToModelEntityType[storeEntityType]; string name = CreateModelName(storeEndMember.Name, usedEndMemberNames); AssociationEndMember end = new AssociationEndMember(name, modelEntityType.GetReferenceType(), multiplicityOverride); end.DeleteBehavior = deleteBehaviorOverride; return end; }
public TestModelBuilder Association( string name, string sourceEntity, RelationshipMultiplicity sourceEndKind, string sourceNavigationProperty, string targetEntity, RelationshipMultiplicity targetEndKind, string targetNavigationProperty) { var sourceEntityType = _model.GetEntityType(sourceEntity); var targetEntityType = _model.GetEntityType(targetEntity); var association = _model.AddAssociationType(name, sourceEntityType, sourceEndKind, targetEntityType, targetEndKind); _model.AddAssociationSet(name + "Set", association); if (sourceNavigationProperty != null) { sourceEntityType.AddNavigationProperty(sourceNavigationProperty, association); } if (targetNavigationProperty != null) { targetEntityType.AddNavigationProperty(targetNavigationProperty, association); } return this; }
private AssociationEndMember CreateAssociationEnd(LoadMethodSessionState session, EntityType type, RelationshipMultiplicity multiplicity, UniqueIdentifierService usedEndNames, OperationAction deleteAction ) { string role = usedEndNames.AdjustIdentifier(type.Name); RefType refType = type.GetReferenceType(); AssociationEndMember end = new AssociationEndMember(role, refType, multiplicity); end.DeleteBehavior = deleteAction; session.RelationshipEndTypeLookup.Add(end, type); return end; }
private static string GetXmlMultiplicity(RelationshipMultiplicity endKind) { switch (endKind) { case RelationshipMultiplicity.Many: return "*"; case RelationshipMultiplicity.One: return "1"; case RelationshipMultiplicity.ZeroOrOne: return "0..1"; default: Debug.Fail("Did you add a new EdmAssociationEndKind?"); return string.Empty; } }
private static EdmMultiplicity GetEdmMultiplicity( RelationshipMultiplicity relMultiplicity) { switch (relMultiplicity) { case RelationshipMultiplicity.Many: return EdmMultiplicity.Many; case RelationshipMultiplicity.One: return EdmMultiplicity.One; case RelationshipMultiplicity.ZeroOrOne: return EdmMultiplicity.ZeroOrOne; default: return EdmMultiplicity.Unknown; } }
private static void Check_two_column_relationship_expected_association_end_multiplicity( Version targetEntityFrameworkVersion, bool column1Nullable, bool column2Nullable, RelationshipMultiplicity expectedSourceEndMultiplicity, RelationshipMultiplicity expectedTargetEndMultiplicity) { var tableDetails = new[] { CreateRow( "catalog", "schema", "source", "Id", 0, isNullable: false, dataType: "int", isIdentiy: true, isPrimaryKey: true) , CreateRow( "catalog", "schema", "source", "Other", 1, isNullable: false, dataType: "int", isIdentiy: false, isPrimaryKey: true), CreateRow( "catalog", "schema", "target", "Id", 0, isNullable: column1Nullable, dataType: "int", isIdentiy: true, isPrimaryKey: true), CreateRow( "catalog", "schema", "target", "Other", 1, isNullable: column2Nullable, dataType: "int", isIdentiy: false, isPrimaryKey: true) }; var relationshipDetails = new List<RelationshipDetailsRow> { CreateRelationshipDetailsRow( "RelationshipId", "name", 0, false, "catalog", "schema", "source", "Id", "catalog", "schema", "target", "Id"), CreateRelationshipDetailsRow( "RelationshipId", "name", 0, false, "catalog", "schema", "source", "Other", "catalog", "schema", "target", "Other") }; var storeModelBuilder = CreateStoreModelBuilder("System.Data.SqlClient", "2008", targetEntityFrameworkVersion); var entityRegister = new StoreModelBuilder.EntityRegister(); storeModelBuilder.CreateEntitySets(tableDetails, new TableDetailsRow[0], entityRegister); var associationTypes = new List<AssociationType>(); var associationSet = storeModelBuilder.TryCreateAssociationSet(relationshipDetails, entityRegister, associationTypes); Assert.Equal(1, associationTypes.Count); Assert.NotNull(associationSet); var associationType = associationTypes[0]; Assert.False(MetadataItemHelper.IsInvalid(associationType)); Assert.Null(associationType.MetadataProperties.SingleOrDefault(p => p.Name == "EdmSchemaErrors")); var sourceEnd = associationType.AssociationEndMembers.FirstOrDefault(); var targetEnd = associationType.AssociationEndMembers.ElementAtOrDefault(1); Assert.Equal(expectedSourceEndMultiplicity, sourceEnd.RelationshipMultiplicity); Assert.Equal(expectedTargetEndMultiplicity, targetEnd.RelationshipMultiplicity); }
public static AssociationType AddAssociationType( this EdmModel model, string name, EntityType sourceEntityType, RelationshipMultiplicity sourceAssociationEndKind, EntityType targetEntityType, RelationshipMultiplicity targetAssociationEndKind, string modelNamespace = null) { DebugCheck.NotNull(model); DebugCheck.NotEmpty(name); DebugCheck.NotNull(sourceEntityType); DebugCheck.NotNull(targetEntityType); var associationType = new AssociationType( name, modelNamespace ?? DefaultModelNamespace, false, DataSpace.CSpace) { SourceEnd = new AssociationEndMember( name + "_Source", sourceEntityType.GetReferenceType(), sourceAssociationEndKind), TargetEnd = new AssociationEndMember( name + "_Target", targetEntityType.GetReferenceType(), targetAssociationEndKind) }; model.AddAssociationType(associationType); return associationType; }
private static AssociationEndMember GenerateAssociationEndMember( SimpleMappingContext mappingContext, AssociationEndMember storeEndMember, UniqueIdentifierService uniqueEndMemberNames, RelationshipMultiplicity multiplicity, OperationAction deleteBehavior) { var storeEntityType = ((EntityType)((RefType)storeEndMember.TypeUsage.EdmType).ElementType); var conceptualEntityType = mappingContext[storeEntityType]; var conceptualEndMember = AssociationEndMember.Create( CreateModelName(storeEndMember.Name, uniqueEndMemberNames), conceptualEntityType.GetReferenceType(), multiplicity, deleteBehavior, null); mappingContext.AddMapping(storeEndMember, conceptualEndMember); return conceptualEndMember; }
/// <summary> /// Return the string for the given enum RelationshipMultiplicity value. /// </summary> /// <param name="multiplicity">RelationshipMultiplicity value.</param> /// <returns>Return the string for the given enum RelationshipMultiplicity value.</returns> private static string GetMultiplicity(RelationshipMultiplicity multiplicity) { switch (multiplicity) { case RelationshipMultiplicity.Many: return XmlConstants.Many; case RelationshipMultiplicity.One: return XmlConstants.One; default: Debug.Assert(multiplicity == RelationshipMultiplicity.ZeroOrOne, "multiplicity == RelationshipMultiplicity.ZeroOrOne"); return XmlConstants.ZeroOrOne; } }