Beispiel #1
0
 protected void SaveSchemaToDatabase(DbContext context)
 {
     using (var ctx = new SchemaVersionContext(context.Database.Connection))
     {
         var entity = new SchemaVersionRow();
         //entity.MigrationId = MigrationAssembly.CreateMigrationId(Strings.InitialCreate);
         entity.CreatedOn = DateTime.UtcNow;
         entity.ModelId   = ModelId;
         entity.VersionId = Assembly.GetExecutingAssembly().GetFileVersion();
         ctx.Version.Add(entity);
         ctx.SaveChanges();
     }
 }
Beispiel #2
0
 protected void CreateSchemaVersionTables(DbContext context)
 {
     using (var ctx = new SchemaVersionContext(context.Database.Connection.ConnectionString))
     {
         //using (new TransactionScope(TransactionScopeOption.Suppress))
         {
             var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
             objectContext.Connection.Open();
             context.Database.ExecuteSqlCommand(objectContext.CreateDatabaseScript());
             var entity = new SchemaVersionRow();
             //entity.MigrationId = MigrationAssembly.CreateMigrationId(Strings.InitialCreate);
             entity.CreatedOn = DateTime.UtcNow;
             entity.ModelId   = ModelId;
             entity.VersionId = Assembly.GetExecutingAssembly().GetFileVersion();
             ctx.Version.Add(entity);
             ctx.SaveChanges();
             objectContext.Connection.Close();
         }
     }
 }
Beispiel #3
0
        public bool CompatibleWithModel(DbContext context, bool throwIfNoMetadata, string id)
        {
            bool ret = false;

            using (var ctx = new SchemaVersionContext(context.Database.Connection))
            {
                if (!Exists(ctx))
                {
                    ret = false;
                }
                else
                {
                    SchemaVersionRow version =
                        (from v in ctx.Version where v.ModelId.Equals(id, StringComparison.OrdinalIgnoreCase) select v)
                        .SingleOrDefault();
                    if (version == null)
                    {
                        ret = false;
                    }
                    else
                    {
                        ret = true;
                    }
                }
            }

            if (throwIfNoMetadata)
            {
                throw new ApplicationException("no schema for " + id);
            }

            return(ret);

            /*
             *          string hash = EdmMetadata.TryGetModelHash(context);
             *          if (hash == null)
             *          {
             *                  if (throwIfNoMetadata)
             *                  {
             *                          throw new ApplicationException("no schema hash");
             *                  }
             *                  return true;
             *          }
             *
             *          if (((IObjectContextAdapter)context).ObjectContext.GetEntitySet(typeof(SchemaMetadata), false) == null)
             *          {
             *                  if (throwIfNoMetadata)
             *                  {
             *                          throw new ApplicationException("no schema mapping");
             *                  }
             *                  return true;
             *          }
             *
             *          string a = context.QueryForModelHash(id);
             *          if (a != null)
             *          {
             *                  return string.Equals(a, hash, StringComparison.Ordinal);
             *          }
             *          if (throwIfNoMetadata)
             *          {
             *                  throw new ApplicationException("no schema hash2");
             *          }
             *
             *          return false;
             * */
        }