本文整理汇总了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;
}
示例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;
}
示例3: CreateDatabase
public void CreateDatabase()
{
using (var nwEntities = new ObjectContext("name=NorthwindAttach"))
{
if (nwEntities.DatabaseExists())
{
nwEntities.DeleteDatabase();
}
nwEntities.CreateDatabase();
Assert.True(nwEntities.DatabaseExists());
}
}
示例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;
}
示例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;
}