Exemple #1
0
        public override void Init()
        {
            XpoDefault.DataLayer = null;
            XpoDefault.Session   = null;
            var Args = new SchemaMismatchEventArgs(this, SchemaStatus.None);

            PrepareDictionary();

            //Check if the schema requires update https://www.devexpress.com/Support/Center/Question/Details/Q245466/determining-if-schema-needs-to-be-updated
            if (XpoDefault.DataLayer == null)
            {
                try
                {
                    using (var CheckSchemaDataLayer = new SimpleDataLayer(Dictionary, CreateSchemaCheckingDataStore()))
                    {
                        //HACK new way to compare schema https://www.devexpress.com/Support/Center/Question/Details/T562023/xpo-how-to-detect-of-chnage-structure-of-database-by-new-change-in-db-model
                        var types  = Dictionary.Classes.Cast <XPClassInfo>().Where(ci => ci.IsPersistent).ToArray();
                        var Result = CheckSchemaDataLayer.UpdateSchema(true, types);
                        if (Result == UpdateSchemaResult.FirstTableNotExists)
                        {
                            OnSchemaMismatch(this, Args);
                        }
                        //HACK the old version of checking the schema https://www.devexpress.com/Support/Center/Question/Details/T189303/xpo-how-to-check-if-db-schema-needs-to-be-changed-without-changing-it
                        //using (var session = new Session(CheckSchemaDataLayer))
                        //{

                        //    session.UpdateSchema();
                        //    //session.CreateObjectTypeRecords();
                        //}
                    }

                    Args.Handled = true;
                }
                catch (SchemaCorrectionNeededException)
                {
                    OnSchemaMismatch(this, Args);
                }

                //catch (DevExpress.Xpo.DB.Exceptions.SchemaCorrectionNeededException)
                //{
                //    OnSchemaMismatch(this, Args);
                //}
                if (Args.Handled)
                {
                    workingStore =
                        XpoDefault.GetConnectionProvider(ConnectionString, AutoCreateOption.SchemaAlreadyExists);
                    DataLayer = new ThreadSafeDataLayer(Dictionary, workingStore);
                }
            }
        }
Exemple #2
0
        //public override void CreateSchema()
        //{
        //    base.CreateSchema();
        //}

        protected override void OnSchemaMismatch(IDataSpaceProvider source, SchemaMismatchEventArgs e)
        {
            base.OnSchemaMismatch(source, e);
        }