本文整理汇总了C#中DbCompiledModel类的典型用法代码示例。如果您正苦于以下问题:C# DbCompiledModel类的具体用法?C# DbCompiledModel怎么用?C# DbCompiledModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DbCompiledModel类属于命名空间,在下文中一共展示了DbCompiledModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateModel_uses_DbCompiledModel_from_ModelStore_when_available
public void CreateModel_uses_DbCompiledModel_from_ModelStore_when_available()
{
var store = new Mock<DbModelStore>();
var dbCompiledModelInStore = new DbCompiledModel();
store.Setup(c => c.TryLoad(It.IsAny<Type>())).Returns(dbCompiledModelInStore);
store.Setup(c => c.Save(It.IsAny<Type>(), It.IsAny<DbModel>()));
try
{
var dependencyResolver = new SingletonDependencyResolver<DbModelStore>(store.Object);
MutableResolver.AddResolver<DbModelStore>(dependencyResolver);
var mockContext = new Mock<LazyInternalContext>(
new Mock<DbContext>().Object, new Mock<IInternalConnection>().Object, null, null, null, null, null)
{
CallBase = true
};
var model = LazyInternalContext.CreateModel(mockContext.Object);
Assert.Same(dbCompiledModelInStore, model);
store.Verify(c => c.TryLoad(It.IsAny<Type>()), Times.Once(),
"should load existing model");
store.Verify(c => c.Save(It.IsAny<Type>(), It.IsAny<DbModel>()), Times.Never(),
"should not call Save when loading model from store");
}
finally //clean up
{
MutableResolver.ClearResolvers();
}
}
示例2: CreateModel_does_not_use_ModelStore_for_HistoryContext
public void CreateModel_does_not_use_ModelStore_for_HistoryContext()
{
var store = new Mock<DbModelStore>();
var dbCompiledModelInStore = new DbCompiledModel();
store.Setup(c => c.TryLoad(It.IsAny<Type>())).Returns(dbCompiledModelInStore);
store.Setup(c => c.Save(It.IsAny<Type>(), It.IsAny<DbModel>()));
try
{
var dependencyResolver = new SingletonDependencyResolver<DbModelStore>(store.Object);
MutableResolver.AddResolver<DbModelStore>(dependencyResolver);
var mockContext = new Mock<LazyInternalContext>(
new MockHistoryContext(), new Mock<IInternalConnection>().Object, null, null, null, null, null)
{
CallBase = true
};
mockContext.Object.ModelProviderInfo = ProviderRegistry.Sql2008_ProviderInfo;
var model = LazyInternalContext.CreateModel(mockContext.Object);
Assert.NotSame(dbCompiledModelInStore, model);
store.Verify(c => c.TryLoad(It.IsAny<Type>()), Times.Never(),
"should not call store for HistoryContext");
store.Verify(c => c.Save(It.IsAny<Type>(), It.IsAny<DbModel>()), Times.Never(),
"should not call store for HistoryContext");
}
finally //clean up
{
MutableResolver.ClearResolvers();
}
}
示例3: OwDbContext
/// <summary>
/// Constructor.
/// 构造函数
/// </summary>
protected OwDbContext(DbCompiledModel model)
: base(model)
{
Logger = NullLogger.Instance;
OwSession = NullOwSession.Instance;
EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
}
示例4: AbpDbContext
/// <summary>
/// Constructor.
/// </summary>
protected AbpDbContext(DbCompiledModel model)
: base(model)
{
Logger = NullLogger.Instance;
AbpSession = NullAbpSession.Instance;
EntityChangedEventHelper = NullEntityChangedEventHelper.Instance;
}
示例5: AddDbCompiledModelAnnotation
public static IEdmModel AddDbCompiledModelAnnotation(this IEdmModel model, DbCompiledModel dbCompiledModel)
{
var annotation = new DbCompiledModelAnnotation(dbCompiledModel);
model.SetAnnotationValue(model, annotation);
return model;
}
示例6: Calculate
/// <summary>
/// Calculates an SHA256 hash of the EDMX from the given code first model. This is the hash stored in
/// the database in the EdmMetadata table in EF 4.1/4.2. The hash is always calculated using a v2 schema
/// as was generated by EF 4.1/4.2 and with the <see cref = "EdmMetadata" /> entity included in the model.
/// </summary>
public virtual string Calculate(DbCompiledModel compiledModel)
{
//Contract.Requires(compiledModel != null);
//Contract.Requires(compiledModel.ProviderInfo != null);
//Contract.Requires(compiledModel.CachedModelBuilder != null);
var providerInfo = compiledModel.ProviderInfo;
var modelBuilder = compiledModel.CachedModelBuilder.Clone();
// Add back in the EdmMetadata class because the hash created by EF 4.1 and 4.2 will contain it.
EdmMetadataContext.ConfigureEdmMetadata(modelBuilder.ModelConfiguration);
var databaseMetadata = modelBuilder.Build(providerInfo).DatabaseMapping.Database;
databaseMetadata.Version = 2.0; // Ensures SSDL version matches that created by EF 4.1/4.2
var stringBuilder = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(
stringBuilder, new XmlWriterSettings
{
Indent = true
}))
{
new SsdlSerializer().Serialize(
databaseMetadata,
providerInfo.ProviderInvariantName,
providerInfo.ProviderManifestToken,
xmlWriter);
}
return ComputeSha256Hash(stringBuilder.ToString());
}
示例7: ChebayDBContext
private ChebayDBContext(DbCompiledModel model, string name)
: base(con, model)
{
tenant_name = name;
Database.SetInitializer<ChebayDBContext>(null);
this.Configuration.LazyLoadingEnabled = false;
}
示例8: QdfDbContext
/// <summary>
/// Constructor.
/// </summary>
protected QdfDbContext(string nameOrConnectionString, DbCompiledModel model)
: base(nameOrConnectionString, model)
{
//Logger = NullLogger.Instance;
QdfSession = NullQdfSession.Instance;
EntityChangedEventHelper = NullEntityChangedEventHelper.Instance;
}
示例9: F1Context
public F1Context(
DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection, bool lazyLoadingEnabled = true,
bool proxyCreationEnabled = true)
: base(existingConnection, model, contextOwnsConnection)
{
SetContextOptions(lazyLoadingEnabled, proxyCreationEnabled);
}
示例10: DbContextBase
public DbContextBase(
string nameOrConnectionString,
DbCompiledModel model,
IExceptionMapper exceptionMapper = null)
: base(nameOrConnectionString, model)
{
SetExceptionMapper(exceptionMapper);
}
示例11: Model
public static DbCompiledModel Model(SqlConnection con)
{
if ((_builder == null) || (_model == null))
{
_builder = new DbModelBuilder();
_builder.Configurations.Add(new ProductConfiguration());
var edm = _builder.Build(con);
_model = edm.Compile();
}
return _model;
}
示例12: DbContextBase
public DbContextBase(
string nameOrConnectionString,
DbCompiledModel model,
IExceptionMapper exceptionMapper = null,
IEntityAdder entityAdder = null,
IEntityUpdater entityUpdater = null,
IEntityDeleter entityDeleter = null,
IEntityDetacher entityDetacher = null)
: base(nameOrConnectionString, model)
{
Init(exceptionMapper, entityAdder, entityUpdater, entityDeleter, entityDetacher);
}
示例13: LazyInternalContext
/// <summary>
/// Constructs a <see cref = "LazyInternalContext" /> for the given <see cref = "DbContext" /> owner that will be initialized
/// on first use.
/// </summary>
/// <param name = "owner">The owner <see cref = "DbContext" />.</param>
/// <param name = "internalConnection">Responsible for creating a connection lazily when the context is used for the first time.</param>
/// <param name = "model">The model, or null if it will be created by convention</param>
public LazyInternalContext(
DbContext owner,
IInternalConnection internalConnection,
DbCompiledModel model,
IDbModelCacheKeyFactory cacheKeyFactory = null)
: base(owner)
{
//Contract.Requires(internalConnection != null);
_internalConnection = internalConnection;
_model = model;
_cacheKeyFactory = cacheKeyFactory ?? new DefaultModelCacheKeyFactory();
_createdWithExistingModel = model != null;
}
示例14: AbpDbContext
/// <summary>
/// Constructor.
/// </summary>
protected AbpDbContext(string nameOrConnectionString, DbCompiledModel model)
: base(nameOrConnectionString, model)
{
InitializeDbContext();
}
示例15: SpSynthDbContext
public SpSynthDbContext(DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection)
: base(existingConnection, model, contextOwnsConnection)
{
}