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


C# ObjectContext.CreateDatabase方法代码示例

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


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

示例1: Create

        /// <summary>
        ///     Used a delegate to do the actual creation once an ObjectContext has been obtained.
        ///     This is factored in this way so that we do the same thing regardless of how we get to
        ///     having an ObjectContext.
        ///     Note however that a context obtained from only a connection will have no model and so
        ///     will result in an empty database.
        /// </summary>
        public virtual bool Create(ObjectContext objectContext)
        {
            //Contract.Requires(objectContext != null);

            objectContext.CreateDatabase();
            return true;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:14,代码来源:DatabaseOperations.cs

示例2: Create

        /// <summary>
        ///     Used a delegate to do the actual creation once an ObjectContext has been obtained.
        ///     This is factored in this way so that we do the same thing regardless of how we get to
        ///     having an ObjectContext.
        ///     Note however that a context obtained from only a connection will have no model and so
        ///     will result in an empty database.
        /// </summary>
        public virtual bool Create(ObjectContext objectContext)
        {
            DebugCheck.NotNull(objectContext);

            objectContext.CreateDatabase();
            return true;
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:14,代码来源:DatabaseOperations.cs

示例3: 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

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