当前位置: 首页>>代码示例>>C#>>正文


C# ObjectContext.DatabaseExists方法代码示例

本文整理汇总了C#中ObjectContext.DatabaseExists方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContext.DatabaseExists方法的具体用法?C# ObjectContext.DatabaseExists怎么用?C# ObjectContext.DatabaseExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectContext的用法示例。


在下文中一共展示了ObjectContext.DatabaseExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDatabase

        public void CreateDatabase()
        {
            using (var nwEntities = new ObjectContext("name=NorthwindAttach"))
            {
                if (nwEntities.DatabaseExists())
                {
                    nwEntities.DeleteDatabase();
                }

                nwEntities.CreateDatabase();

                Assert.True(nwEntities.DatabaseExists());
            }
        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:14,代码来源:CreateDatabaseTests.cs

示例2: EntityConnectionFactory_CreateTransientEntityConnection_InitializesDataSchema

        public void EntityConnectionFactory_CreateTransientEntityConnection_InitializesDataSchema()
        {
            EntityConnection connection = EntityConnectionFactory.CreateTransient(NorthwindObjectContext.DefaultConnectionString);

            using (ObjectContext context = new ObjectContext(connection))
            {
                Assert.IsTrue(context.DatabaseExists());
                Assert.AreEqual(0, context.CreateObjectSet<Product>().Count(), "Zero rows in the fake table");
            }
        }
开发者ID:DeadlyEmbrace,项目名称:effort,代码行数:10,代码来源:EntityConnectionFactoryFixture.cs

示例3: Exists

        public virtual bool Exists(ObjectContext objectContext)
        {
            //Contract.Requires(objectContext != null);

            try
            {
                return objectContext.DatabaseExists();
            }
            catch (Exception)
            {
                // In situations where the user does not have access to the master database
                // the above DatabaseExists call fails and throws an exception.  Rather than
                // just let that exception escape to the caller we instead try a different
                // approach to see if the database really does exist or not.  The approach
                // is to try to open a connection to the database.  If this succeeds then
                // we know that the database exists.  If it fails then the database may
                // not exist or there may be some other issue connecting to it.  In either
                // case for the purpose of this call we assume that it does not exist and
                // return false since this functionally gives the best experience in most
                // scenarios.
                if (objectContext.Connection.State
                    == ConnectionState.Open)
                {
                    return true;
                }
                try
                {
                    objectContext.Connection.Open();
                    return true;
                }
                catch (EntityException)
                {
                    return false;
                }
                finally
                {
                    objectContext.Connection.Close();
                }
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:40,代码来源:DatabaseOperations.cs

示例4: CreateEntityConnection

        /// <summary>
        ///     Creates a new EntityConnection object and initializes its underlying database.
        /// </summary>
        /// <param name="metadata"> The metadata of the database. </param>
        /// <param name="connection"> The wrapped connection object. </param>
        /// <returns> The EntityConnection object. </returns>
        private static EntityConnection CreateEntityConnection(
            MetadataWorkspace metadata,
            DbConnection connection)
        {
            #if !EFOLD
            EntityConnection entityConnection =
                new EntityConnection(metadata, connection, true);
            #else
            EntityConnection entityConnection =
                new EntityConnection(metadata, connection);

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

            owned.SetValue(entityConnection, false);
            #endif

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

            return entityConnection;
        }
开发者ID:CodingGorilla,项目名称:effort,代码行数:36,代码来源:EntityConnectionFactory.cs

示例5: Exists

        public virtual bool Exists(ObjectContext objectContext)
        {
            DebugCheck.NotNull(objectContext);

            return objectContext.DatabaseExists();
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:6,代码来源:DatabaseOperations.cs

示例6: CreateInspectedFakeEntityConnection

        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;
        }
开发者ID:DeadlyEmbrace,项目名称:effort,代码行数:80,代码来源:EntityConnectionHelper.cs


注:本文中的ObjectContext.DatabaseExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。