Пример #1
0
        /// <summary>
        ///     Returns a metadata workspace that is rewritten in order to be compatible the
        ///     Effort provider.
        /// </summary>
        /// <param name="entityConnectionString">
        ///     The entity connection string that references the original metadata.
        /// </param>
        /// <returns>
        ///     The rewritten metadata.
        /// </returns>
        private static MetadataWorkspace GetEffortCompatibleMetadataWorkspace(
            ref string entityConnectionString)
        {
            EffortProviderConfiguration.VerifyProvider();

            entityConnectionString = GetFullEntityConnectionString(entityConnectionString);

            EntityConnectionStringBuilder connectionStringBuilder =
                new EntityConnectionStringBuilder(entityConnectionString);

            return(MetadataWorkspaceStore.GetMetadataWorkspace(
                       connectionStringBuilder.Metadata,
                       metadata => MetadataWorkspaceHelper.Rewrite(
                           metadata,
                           EffortProviderConfiguration.ProviderInvariantName,
                           EffortProviderManifestTokens.Version1)));
        }
        /// <summary>
        ///     Creates an EffortConnection object with a connection string that represents the
        ///     specified parameter values.
        /// </summary>
        /// <param name="instanceId"> The instance id. </param>
        /// <param name="dataLoader"> The data loader. </param>
        /// <returns> The EffortConnection object. </returns>
        private static EffortConnection Create(string instanceId, IDataLoader dataLoader)
        {
            EffortProviderConfiguration.VerifyProvider();

            EffortConnectionStringBuilder connectionString =
                new EffortConnectionStringBuilder();

            connectionString.InstanceId = instanceId;

            if (dataLoader != null)
            {
                connectionString.DataLoaderType     = dataLoader.GetType();
                connectionString.DataLoaderArgument = dataLoader.Argument;
            }

            EffortConnection connection = new EffortConnection();

            connection.ConnectionString = connectionString.ConnectionString;

            return(connection);
        }
Пример #3
0
        private static EntityConnection CreateInspectedFakeEntityConnection(string entityConnectionString, IResultSetComposer resultSetComposer, bool createFake, IDataLoader dataLoader)
        {
            EntityConnectionStringBuilder connectionString = new EntityConnectionStringBuilder(entityConnectionString);

            if (!string.IsNullOrEmpty(connectionString.Name))
            {
                string resolvedConnectionString = ConfigurationManager.ConnectionStrings[connectionString.Name].ConnectionString;
                connectionString = new EntityConnectionStringBuilder(resolvedConnectionString);
            }

            List <XElement> csdl = new List <XElement>();
            List <XElement> ssdl = new List <XElement>();
            List <XElement> msl  = new List <XElement>();

            MetadataWorkspaceHelper.ParseMetadata(connectionString.Metadata, csdl, ssdl, msl);

            foreach (XElement ssdlFile in ssdl)
            {
                XAttribute providerAttribute = ssdlFile.Attribute("Provider");
                XAttribute providerManifestTokenAttribute = ssdlFile.Attribute("ProviderManifestToken");

                if (createFake)
                {
                    EffortProviderConfiguration.VerifyProvider();
                    UniversalStorageSchemaModifier.Instance.Modify(ssdlFile, new EffortProviderInformation());
                }

                string oldProviderInvariantName = providerAttribute.Value;
                string oldProviderManifestToken = providerManifestTokenAttribute.Value;

                providerAttribute.Value = DataReaderInspectorProviderConfiguration.ProviderInvariantName;
                providerManifestTokenAttribute.Value = string.Format("{0};{1}", oldProviderInvariantName, oldProviderManifestToken);
            }

            MetadataWorkspace convertedWorkspace = MetadataWorkspaceHelper.CreateMetadataWorkspace(csdl, ssdl, msl);

            DbConnection storeConnection = null;

            if (createFake)
            {
                storeConnection = Effort.DbConnectionFactory.CreateTransient(dataLoader);
            }
            else
            {
                storeConnection = ProviderHelper.CreateConnection(connectionString.Provider);
                storeConnection.ConnectionString = connectionString.ProviderConnectionString;
            }

            DbConnectionWrapper inspectorConnection = new DataReaderInspectorConnection(resultSetComposer);

            inspectorConnection.WrappedConnection = storeConnection;

#if !EFOLD
            EntityConnection entityConnection =
                new EntityConnection(convertedWorkspace, inspectorConnection, true);
#else
            EntityConnection entityConnection =
                new EntityConnection(convertedWorkspace, inspectorConnection);

            FieldInfo owned =
                typeof(EntityConnection)
                .GetField(
                    "_userOwnsStoreConnection",
                    BindingFlags.Instance | BindingFlags.NonPublic);

            owned.SetValue(entityConnection, false);
#endif

            if (createFake)
            {
                using (ObjectContext objectContext = new ObjectContext(entityConnection))
                {
                    if (!objectContext.DatabaseExists())
                    {
                        objectContext.CreateDatabase();
                    }
                }
            }

            return(entityConnection);
        }