src/Misc/EFTools/EntityDesignModel/ModelHelper.cs
/// <summary>
///     Helper method to find a fragment inside an ETM of a certain kind that maps a C and S entity, and optionally
///     creates one if none exists.
/// </summary>
/// <param name="cpc"></param>
/// <param name="conceptualEntityType">The conceptual side entity</param>
/// <param name="storageEntityType">The storage side entity</param>
/// <param name="kind">Looks for an EntityTypeMapping of this kind and then looks for a fragment inside it</param>
/// <param name="createIfNoneFound">Create one of the Kind passed in if none of that kind are found</param>
/// <returns>May return null if you pass false to 'createIfNoneFound'</returns>
Helper method to find a fragment inside an ETM of a certain kind that maps a C and S entity, and optionally
creates one if none exists.
Helper method to find a fragment inside an ETM of a certain kind that maps a C and S entity and optionally creates one if none exists .
internal static MappingFragment FindMappingFragment(
            CommandProcessorContext cpc, EntityType conceptualEntityType, EntityType storageEntityType, EntityTypeMappingKind kind,
            bool createIfNoneFound)
        {
            Debug.Assert(conceptualEntityType != null, "null conceptualEntityType");
            Debug.Assert(conceptualEntityType.EntityModel.IsCSDL, "conceptualEntityType is not CSDL");
            Debug.Assert(storageEntityType != null, "null storageEntityType");
            Debug.Assert(storageEntityType.EntityModel.IsCSDL != true, "storageEntityType is not SSDL");
            var ses = storageEntityType.EntitySet as StorageEntitySet;
            Debug.Assert(ses != null, "FindMappingFragment: StorageEntitySet is null");
            var entityTypeMapping = FindEntityTypeMapping(cpc, conceptualEntityType, kind, false);
            MappingFragment mappingFragment = null;
            if (entityTypeMapping == null)
            {
                if (createIfNoneFound == false)
                {
                    return null;
                }
                var createETM = new CreateEntityTypeMappingCommand(
                    conceptualEntityType as ConceptualEntityType,
                    kind);
                CommandProcessor.InvokeSingleCommand(cpc, createETM);
                entityTypeMapping = createETM.EntityTypeMapping;
            }
            else
            {
                foreach (var frag in entityTypeMapping.MappingFragments())
                {
                    if (frag.StoreEntitySet.Target == ses)
                    {
                        mappingFragment = frag;
                        break;
                    }
                }
            }
            Debug.Assert(entityTypeMapping != null, "entityTypeMapping is null");
            if (mappingFragment == null
                && createIfNoneFound
                && cpc != null)
            {
                var cmd = new CreateMappingFragmentCommand(conceptualEntityType, storageEntityType, kind);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                mappingFragment = cmd.MappingFragment;
                Debug.Assert(mappingFragment != null, "MappingFragment from CreateMappingFragmentCommand should not be null");
            }
            return mappingFragment;
        }
internal static MappingFragment FindMappingFragment ( CommandProcessorContext cpc , EntityType conceptualEntityType , EntityType storageEntityType , EntityTypeMappingKind kind , bool createIfNoneFound ) { Debug . Assert ( conceptualEntityType != null , " " ) ; Debug . Assert ( conceptualEntityType . EntityModel . IsCSDL , " " ) ; Debug . Assert ( storageEntityType != null , " " ) ; Debug . Assert ( storageEntityType . EntityModel . IsCSDL != true , " " ) ; var ses = storageEntityType . EntitySet as StorageEntitySet ; Debug . Assert ( ses != null , " " ) ; var entityTypeMapping = FindEntityTypeMapping ( cpc , conceptualEntityType , kind , false ) ; MappingFragment mappingFragment = null ; if ( entityTypeMapping == null ) { if ( createIfNoneFound == false ) { return null ; } var createETM = new CreateEntityTypeMappingCommand ( conceptualEntityType as ConceptualEntityType , kind ) ; CommandProcessor . InvokeSingleCommand ( cpc , createETM ) ; entityTypeMapping = createETM . EntityTypeMapping ; } else { foreach ( var frag in entityTypeMapping . MappingFragments ( ) ) { if ( frag . StoreEntitySet . Target == ses ) { mappingFragment = frag ; break ; } } } Debug . Assert ( entityTypeMapping != null , " " ) ; if ( mappingFragment == null && createIfNoneFound && cpc != null ) { var cmd = new CreateMappingFragmentCommand ( conceptualEntityType , storageEntityType , kind ) ; CommandProcessor . InvokeSingleCommand ( cpc , cmd ) ; mappingFragment = cmd . MappingFragment ; Debug . Assert ( mappingFragment != null , " " ) ; } return mappingFragment ; }
Helper method to find a fragment inside an ETM of a certain kind that maps a C and S entity, and optionally
creates one if none exists.
Helper method to find a fragment inside an ETM of a certain kind that maps a C and S entity and optionally creates one if none exists .
// the S-Side entitySet // find/create the ETM for this entity // we don't want to create, and we don't even have an ETM, then just return null // found an existing ETM, is there also a mapping fragment already? // if couldn't find an existing fragment, create it
May return null if you pass false to 'createIfNoneFound'
May return null if you pass false to ' createIfNoneFound '
cpc
CommandProcessorContext
None
conceptualEntityType
EntityType
The conceptual side entity
The conceptual side entity
storageEntityType
EntityType
The storage side entity
The storage side entity
kind
EntityTypeMappingKind
Looks for an EntityTypeMapping of this kind and then looks for a fragment inside it
Looks for an EntityTypeMapping of this kind and then looks for a fragment inside it
createIfNoneFound
bool
Create one of the Kind passed in if none of that kind are found
Create one of the Kind passed in if none of that kind are found