src/Misc/EFTools/EntityDesignModel/ModelHelper.cs
/// <summary>
///     A helper method that tries to find one of the two types of ETMs
/// </summary>
A helper method that tries to find one of the two types of ETMs
A helper method that tries to find one of the two types of ETMs
internal static EntityTypeMapping FindEntityTypeMapping(
            CommandProcessorContext cpc, EntityType conceptualEntityType, EntityTypeMappingKind kind, bool createIfNoneFound)
        {
            foreach (var etm in conceptualEntityType.GetAntiDependenciesOfType<EntityTypeMapping>())
            {
                if (etm.EntitySetMapping.Name.Target == conceptualEntityType.EntitySet)
                {
                    if (etm.ModificationFunctionMapping != null)
                    {
                        if (kind == EntityTypeMappingKind.Function)
                        {
                            return etm;
                        }
                        continue;
                    }
                    if (etm.TypeName.Status == (int)BindingStatus.Known)
                    {
                        Debug.Assert(
                            etm.TypeName.Bindings.Count <= 1 && etm.TypeName.IsTypeOfs.Count <= 1,
                            "etm.TypeName.Bindings.Count(" + etm.TypeName.Bindings.Count
                            + ") should be <= 1 and etm.TypeName.IsTypeOfs.Count(" + etm.TypeName.IsTypeOfs.Count + ") should be <= 1");
                        if (etm.TypeName.IsTypeOfs[0]
                            && kind == EntityTypeMappingKind.IsTypeOf)
                        {
                            return etm;
                        }
                        else if (etm.TypeName.IsTypeOfs[0] == false
                                 && kind == EntityTypeMappingKind.Default)
                        {
                            return etm;
                        }
                    }
                    else
                    {
                        if (etm.TypeName.RefName.Contains(EntityTypeMapping.IsTypeOf)
                            && kind == EntityTypeMappingKind.IsTypeOf)
                        {
                            return etm;
                        }
                        else if (kind == EntityTypeMappingKind.Default)
                        {
                            return etm;
                        }
                    }
                }
            }
            if (createIfNoneFound && cpc != null)
            {
                var createETM = new CreateEntityTypeMappingCommand(
                    conceptualEntityType as ConceptualEntityType,
                    kind);
                CommandProcessor.InvokeSingleCommand(cpc, createETM);
                Debug.Assert(createETM.EntityTypeMapping != null, "createETM.EntityTypeMapping should not be null");
                return createETM.EntityTypeMapping;
            }
            return null;
        }
internal static EntityTypeMapping FindEntityTypeMapping ( CommandProcessorContext cpc , EntityType conceptualEntityType , EntityTypeMappingKind kind , bool createIfNoneFound ) { foreach ( var etm in conceptualEntityType . GetAntiDependenciesOfType < EntityTypeMapping > ( ) ) { if ( etm . EntitySetMapping . Name . Target == conceptualEntityType . EntitySet ) { if ( etm . ModificationFunctionMapping != null ) { if ( kind == EntityTypeMappingKind . Function ) { return etm ; } continue ; } if ( etm . TypeName . Status == ( int ) BindingStatus . Known ) { Debug . Assert ( etm . TypeName . Bindings . Count <= 1 && etm . TypeName . IsTypeOfs . Count <= 1 , " " + etm . TypeName . Bindings . Count + " " + etm . TypeName . IsTypeOfs . Count + " " ) ; if ( etm . TypeName . IsTypeOfs [ 0 ] && kind == EntityTypeMappingKind . IsTypeOf ) { return etm ; } else if ( etm . TypeName . IsTypeOfs [ 0 ] == false && kind == EntityTypeMappingKind . Default ) { return etm ; } } else { if ( etm . TypeName . RefName . Contains ( EntityTypeMapping . IsTypeOf ) && kind == EntityTypeMappingKind . IsTypeOf ) { return etm ; } else if ( kind == EntityTypeMappingKind . Default ) { return etm ; } } } } if ( createIfNoneFound && cpc != null ) { var createETM = new CreateEntityTypeMappingCommand ( conceptualEntityType as ConceptualEntityType , kind ) ; CommandProcessor . InvokeSingleCommand ( cpc , createETM ) ; Debug . Assert ( createETM . EntityTypeMapping != null , " " ) ; return createETM . EntityTypeMapping ; } return null ; }
A helper method that tries to find one of the two types of ETMs
A helper method that tries to find one of the two types of ETMs
// v1 assumption, ETM is bound to a single type // if we are fully bound, then we can just check to see if the binding is using IsTypeOfs // if we aren't bound, then all we can do is a string compare // if couldn't find an existing fragment, create it
cpc
CommandProcessorContext
conceptualEntityType
EntityType
kind
EntityTypeMappingKind
createIfNoneFound
bool