本文整理汇总了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());
}
}
示例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");
}
}
示例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();
}
}
}
示例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: Exists
public virtual bool Exists(ObjectContext objectContext)
{
DebugCheck.NotNull(objectContext);
return objectContext.DatabaseExists();
}
示例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;
}