Ejemplo n.º 1
0
        private DevExpress.Xpo.DB.IDataStore CreateNewDataStore(IConfiguration configuration, string Id)
        {
            var ConnectionStrings = configuration.GetSection("ConnectionStrings").AsEnumerable();
            List <KeyValuePair <string, string> > AutoCreateOptionsFromConfig = configuration.GetSection("DatabaseAutoCreateOptions").AsEnumerable().ToList();

            AutoCreateOptions = new Dictionary <string, string>();
            foreach (KeyValuePair <string, string> Value in AutoCreateOptionsFromConfig)
            {
                if (Value.Value == null)
                {
                    continue;
                }

                string[] Split = Value.Key?.Split(':');
                if (Split.Length > 1)
                {
                    AutoCreateOptions.Add(Split[1], Value.Value);
                }
            }

            if (!AutoCreateOptions.ContainsKey(Id))
            {
                throw new ArgumentException($"Missing AutoCreateOptions:{Id}");
            }


            AutoCreateOption autoCreateOptionEnum = AutoCreateOption.None;

            switch (AutoCreateOptions[Id])
            {
            case "DatabaseAndSchema":
                autoCreateOptionEnum = AutoCreateOption.DatabaseAndSchema;
                break;

            case "SchemaOnly":
                autoCreateOptionEnum = AutoCreateOption.SchemaOnly;
                break;

            case "None ":
                autoCreateOptionEnum = AutoCreateOption.None;
                break;

            case "SchemaAlreadyExists":
                autoCreateOptionEnum = AutoCreateOption.SchemaAlreadyExists;
                break;
            }

            var ConnectionString = configuration.GetConnectionString(Id);

            IDisposable[] DisposableObjects = null;
            //TODO read autocreate options from the config
            DevExpress.Xpo.DB.IDataStore DataStore = XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOptionEnum, out DisposableObjects);
            return(DataStore);
        }
Ejemplo n.º 2
0
        public static void SetThreadSafeDataLayer(out ThreadSafeDataLayer Tsdl, string conn)
        {
            // Code that runs on application startup
            DevExpress.Xpo.Metadata.XPDictionary dict =
                new DevExpress.Xpo.Metadata.ReflectionDictionary();
            dict.GetDataStoreSchema(typeof(NewNetServicesModule).Assembly);
            DevExpress.Xpo.DB.IDataStore store =
                DevExpress.Xpo.XpoDefault
                .GetConnectionProvider(conn,
                                       DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
            store = new DevExpress.Xpo.DB.DataCacheNode(new DevExpress.Xpo.DB.DataCacheRoot(store));
            var layer = new DevExpress.Xpo.ThreadSafeDataLayer(dict, store);

            Tsdl = layer;
        }
        private void InitXpoDal()
        {
            // for SQL Express
            //string connStr = @"Data Source=.\sqlexpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\MvcGridView.mdf;User Instance=true;";

            // for SQL Server
            string connStr = @"Data Source=(local);Integrated Security=true;AttachDbFilename=|DataDirectory|\MvcGridView.mdf;";

            SqlConnection conn = new SqlConnection(connStr);

            DevExpress.Xpo.Metadata.XPDictionary dict  = new DevExpress.Xpo.Metadata.ReflectionDictionary();
            DevExpress.Xpo.DB.IDataStore         store = DevExpress.Xpo.XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);
            dict.GetDataStoreSchema(typeof(Order).Assembly);  // <<< initialize the XPO dictionary
            XpoDefault.DataLayer = new ThreadSafeDataLayer(dict, store);
            XpoDefault.Session   = null;
        }