src/Shared/EntityFramework/Infrastructure/EdmxWriter.cs
/// <summary>
/// Uses Code First with the given context and writes the resulting Entity Data Model to the given
/// writer in EDMX form.  This method can only be used with context instances that use Code First
/// and create the model internally.  The method cannot be used for contexts created using Database
/// First or Model First, for contexts created using a pre-existing <see cref="ObjectContext" />, or
/// for contexts created using a pre-existing <see cref="DbCompiledModel" />.
/// </summary>
/// <param name="context"> The context. </param>
/// <param name="writer"> The writer. </param>
Uses Code First with the given context and writes the resulting Entity Data Model to the given
writer in EDMX form.  This method can only be used with context instances that use Code First
and create the model internally.  The method cannot be used for contexts created using Database
First or Model First, for contexts created using a pre-existing , or
for contexts created using a pre-existing .
Uses Code First with the given context and writes the resulting Entity Data Model to the given writer in EDMX form . This method can only be used with context instances that use Code First and create the model internally . The method cannot be used for contexts created using Database First or Model First for contexts created using a pre - existing or for contexts created using a pre - existing .
public static void WriteEdmx(DbContext context, XmlWriter writer)
        {
            Check.NotNull(context, "context");
            Check.NotNull(writer, "writer");
            var internalContext = context.InternalContext;
            if (internalContext is EagerInternalContext)
            {
                throw Error.EdmxWriter_EdmxFromObjectContextNotSupported();
            }
            var modelBeingInitialized = internalContext.ModelBeingInitialized;
            if (modelBeingInitialized != null)
            {
                WriteEdmx(modelBeingInitialized, writer);
                return;
            }
            var compiledModel = internalContext.CodeFirstModel;
            if (compiledModel == null)
            {
                throw Error.EdmxWriter_EdmxFromModelFirstNotSupported();
            }
            var modelStore = DbConfiguration.DependencyResolver.GetService<DbModelStore>();
            if (modelStore != null)
            {
                var storedModel = modelStore.TryGetEdmx(context.GetType());
                if (storedModel != null)
                {
                    storedModel.WriteTo(writer);
                    return;
                }
            }
            var cachedModelBuilder = compiledModel.CachedModelBuilder;
            if (cachedModelBuilder == null)
            {
                throw Error.EdmxWriter_EdmxFromRawCompiledModelNotSupported();
            }
            var builder = cachedModelBuilder.Clone();
            WriteEdmx(
                internalContext.ModelProviderInfo == null
                    ? builder.Build(internalContext.Connection)
                    : builder.Build(internalContext.ModelProviderInfo),
                writer);
        }
public static void WriteEdmx ( DbContext context , XmlWriter writer ) { Check . NotNull ( context , " " ) ; Check . NotNull ( writer , " " ) ; var internalContext = context . InternalContext ; if ( internalContext is EagerInternalContext ) { throw Error . EdmxWriter_EdmxFromObjectContextNotSupported ( ) ; } var modelBeingInitialized = internalContext . ModelBeingInitialized ; if ( modelBeingInitialized != null ) { WriteEdmx ( modelBeingInitialized , writer ) ; return ; } var compiledModel = internalContext . CodeFirstModel ; if ( compiledModel == null ) { throw Error . EdmxWriter_EdmxFromModelFirstNotSupported ( ) ; } var modelStore = DbConfiguration . DependencyResolver . GetService < DbModelStore > ( ) ; if ( modelStore != null ) { var storedModel = modelStore . TryGetEdmx ( context . GetType ( ) ) ; if ( storedModel != null ) { storedModel . WriteTo ( writer ) ; return ; } } var cachedModelBuilder = compiledModel . CachedModelBuilder ; if ( cachedModelBuilder == null ) { throw Error . EdmxWriter_EdmxFromRawCompiledModelNotSupported ( ) ; } var builder = cachedModelBuilder . Clone ( ) ; WriteEdmx ( internalContext . ModelProviderInfo == null ? builder . Build ( internalContext . Connection ) : builder . Build ( internalContext . ModelProviderInfo ) , writer ) ; }
Uses Code First with the given context and writes the resulting Entity Data Model to the given
writer in EDMX form.
Uses Code First with the given context and writes the resulting Entity Data Model to the given writer in EDMX form .
context
DbContext
None
writer
XmlWriter
None