Ejemplo n.º 1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     XpoDefault.ConnectionString = SQLiteConnectionProvider.GetConnectionString(@"nwind.sqlite");
     Application.Run(new Form1());
 }
        static void Main()
        {
            ConnectionProviderSql provider =
                (ConnectionProviderSql)XpoDefault.GetConnectionProvider(SQLiteConnectionProvider.GetConnectionString(@"CustomCommand.sqlite"),
                                                                        AutoCreateOption.DatabaseAndSchema);

            provider.RegisterCustomFunctionOperator(new GetMonthFunction());
            XPDictionary dict = new ReflectionDictionary();

            dict.CustomFunctionOperators.Add(new GetMonthFunction());
            XpoDefault.DataLayer = new SimpleDataLayer(dict, provider);
            CreateData();

            using (Session session = new Session()) {
                XPView view = new XPView(session, typeof(Order));
                view.AddProperty("Month", "custom('GetMonth', OrderDate)");

                foreach (ViewRecord prop in view)
                {
                    Console.WriteLine(prop["Month"]);
                }

                var list = from o in new XPQuery <Order>(session)
                           where o.OrderName == "Chai"
                           select new { Month = GetMonthFunction.GetMonth(o.OrderDate) };

                foreach (var item in list)
                {
                    Console.WriteLine(item.Month);
                }
            }
            Console.WriteLine("done\npress any key to exit ..");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public App()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            try
            {
                var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);



                var    filePath         = Path.Combine(documentsPath, "XpoXamarin.db");
                string connectionString = SQLiteConnectionProvider.GetConnectionString(filePath) + ";Cache=Shared;";



                XpoHelper.InitXpo(connectionString);



                var UoW = XpoHelper.CreateUnitOfWork();

                var count = UoW.Query <Item>().Count();
                MainPage = new MainPage(filePath, count);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                throw exception;
            }
        }
Ejemplo n.º 4
0
        public DictionaryManager(string databaseName)
        {
            DirectoryInfo directory        = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "Dictionary"));
            string        connectionString = SQLiteConnectionProvider.GetConnectionString(Path.Combine(directory.FullName, databaseName));

            XpoDefault.DataLayer = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema);
            XpoDefault.Session   = null;

            UnitOfWork = new UnitOfWork();
        }
Ejemplo n.º 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string connectionString = SQLiteConnectionProvider.GetConnectionString(@"nwind.sqlite");

            using (IDbConnection connection = new SQLiteConnection(connectionString)) {
                InitializeDataLayer(connection);
                Application.Run(new Form1());
            }
        }
Ejemplo n.º 6
0
        public App()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            //MSSqlServer

            //string connectionString = MSSqlConnectionProvider.GetConnectionString("YOUR_SERVER_NAME", "sa", "", "XamarinDemo");

            //SQLite

            var    filePath         = Path.Combine(documentsPath, "xpoXamarinDemo.db");
            string connectionString = SQLiteConnectionProvider.GetConnectionString(filePath) + ";Cache=Shared;";

            //In-memory data store with saving/loading from the xml file

            //var filePath = Path.Combine(documentsPath, "xpoXamarinDemo.xml");
            //string connectionString = InMemoryDataStore.GetConnectionString(filePath);

            XpoHelper.InitXpo(connectionString);
            var            uoW     = XpoHelper.CreateUnitOfWork();
            XPQuery <Item> xPQuery = uoW.Query <Item>(); //Similar to XPCollection


            XPCollection <Item> ItemsXpCollection = new XPCollection <Item>();//HACK For XPCollection use criteria in constructor or filter

            //ItemsXpCollection.Filter = new BinaryOperator("", "");

            //var queryResult= xPQuery.Where(e => e.Description == "algo"); //Better

            //var Reuslt = ItemsXpCollection.Where(e => e.Description == "algo"); //Ineficiente  load whole collection


            if (!xPQuery.Any())
            {
                for (int i = 0; i < 1000; i++)
                {
                    Item Object = new Item(uoW);
                    Object.Description = "Item number:" + i.ToString();
                    Object.Index       = i;
                }
                if (uoW.InTransaction)
                {
                    uoW.CommitChanges();
                }
            }



            MainPage = new MainPage();
        }
Ejemplo n.º 7
0
        private static void StartConnectionConfigDb()
        {
            // Retrieve the Data Store specific connection string.
            string connectionString  = MSSqlConnectionProvider.GetConnectionString(@"DBSRV\QWERTY", @"user02", @"8a0IucJ@Nx1Qy5HfFrX0Ob3m", @"Sales");
            string connectionString1 = SQLiteConnectionProvider.GetConnectionString(@"D:\TEMP\SQLite\SQLITEDB1.db3");
            //
            IDataLayer dataLayer = XpoDefault.GetDataLayer(connectionString1, AutoCreateOption.DatabaseAndSchema);

            XpoDefault.DataLayer = dataLayer;
            //Session session = new Session();
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            //HACK https://documentation.devexpress.com/XPO/119377/Getting-Started/Getting-Started-with-NET-Core
            //string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            //string connectionString = SQLiteConnectionProvider.GetConnectionString(Path.Combine(appDataPath, "myXpoApp.db"));


            string connectionString = SQLiteConnectionProvider.GetConnectionString("myXpoApp.db");

            XpoDefault.DataLayer = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema);



            UnitOfWork UoW = new UnitOfWork();

            if (!UoW.Query <Product>().Any())
            {
                Category BestFoodInTheWorld = new Category(UoW)
                {
                    Code = "001", Name = "Best food in the world"
                };

                Category HealtyFood = new Category(UoW)
                {
                    Code = "002", Name = "Healty Food"
                };

                Product Hamburger = new Product(UoW);
                Hamburger.Name        = "Rocco's hamburger";
                Hamburger.Description = "is a cheeseburger with cheese inside the meat instead of on top, resulting in a melted core of cheese.";
                Hamburger.Code        = "001";
                Hamburger.Category    = BestFoodInTheWorld;
                Product Pizza = new Product(UoW);
                Pizza.Name        = "Pizza";
                Pizza.Description = "Pizza Margherita is a typical Neapolitan pizza, made with San Marzano tomatoes, mozzarella fior di latte, fresh basil, salt and extra-virgin olive oil";
                Pizza.Code        = "002";
                Pizza.Category    = BestFoodInTheWorld;
                Product Tacos = new Product(UoW);
                Tacos.Name        = "Tacos";
                Tacos.Description = "Carne Asada Tacos. Carne asada tacos are delicious, flank steak tacos with a few simple ingredients and tons of flavor";
                Tacos.Code        = "003";
                Tacos.Category    = BestFoodInTheWorld;


                Product Salad = new Product(UoW)
                {
                    Name = "Salad", Description = "Just a salad", Code = "004", Category = HealtyFood
                };
            }
            UoW.CommitChanges();
            CreateWebHostBuilder(args).Build().Run();
        }
        protected override async void OnInitialized()
        {
            InitializeComponent();



            Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;



            DataStore = new SyncDataStore(Identity, false, "http://192.168.1.64/BIT.Xpo.Sync.ServerNew/api/Sync");

            try
            {
                var MainPath    = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                var CacheShared = ";Cache=Shared;";
                var MainDb      = Path.Combine(MainPath, "MainDb.db");
                Debug.WriteLine(string.Format("{0}:{1}", "MainDb", MainDb));
                var Log = Path.Combine(MainPath, "Log.db");
                Debug.WriteLine(string.Format("{0}:{1}", "Log", Log));



                DataStore.Initialize(

                    SQLiteConnectionProvider.GetConnectionString(MainDb) + CacheShared,
                    SQLiteConnectionProvider.GetConnectionString(Log) + CacheShared, true, AutoCreateOption.DatabaseAndSchema, new Assembly[] { typeof(Demo.ORM.CustomBaseObject).Assembly });
                XpoDefault.DataLayer = new SimpleDataLayer(DataStore);

                SyncDataStore.EnableTransactionHistory = true;
                DataStore.PullModification();

                UnitOfWork UoW = new UnitOfWork();
                CreateInitialData(UoW);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(string.Format("{0}:{1}", "exception.Message", exception.Message));
                if (exception.InnerException != null)
                {
                    Debug.WriteLine(string.Format("{0}:{1}", "exception.InnerException.Message", exception.InnerException.Message));
                }
                Debug.WriteLine(string.Format("{0}:{1}", " exception.StackTrace", exception.StackTrace));
            }



            await NavigationService.NavigateAsync("NavigationPage/MainPage");
        }
Ejemplo n.º 10
0
        static void Main()
        {
#if EASYTEST
            DevExpress.ExpressApp.Win.EasyTest.EasyTestRemotingRegistration.Register();
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            EditModelPermission.AlwaysGranted = System.Diagnostics.Debugger.IsAttached;
            Tracing.LocalUserAppDataPath      = Application.LocalUserAppDataPath;
            Tracing.Initialize();
            TypicalDXeXpressAppProject_DoSoWindowsFormsApplication winApplication = new TypicalDXeXpressAppProject_DoSoWindowsFormsApplication();

            string connectionString = SQLiteConnectionProvider.GetConnectionString("DoSo_SampleXAFApp6.db", "random_password");
            XpoDefault.DataLayer = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema);

            winApplication.SplashScreen = new DevExpress.ExpressApp.Win.Utils.DXSplashScreen("DoSo_Logo.png");
            //if (ConfigurationManager.ConnectionStrings["ConnectionString"] != null)
            //{
            //    winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            //}

            winApplication.ConnectionString = connectionString;

#if EASYTEST
            if (ConfigurationManager.ConnectionStrings["EasyTestConnectionString"] != null)
            {
                winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["EasyTestConnectionString"].ConnectionString;
            }
#endif
            if (System.Diagnostics.Debugger.IsAttached && winApplication.CheckCompatibilityType == CheckCompatibilityType.DatabaseSchema)
            {
                winApplication.DatabaseUpdateMode = DatabaseUpdateMode.UpdateDatabaseAlways;
            }
            try
            {
                winApplication.Setup();
                winApplication.Start();
            }
            catch (Exception e)
            {
                winApplication.HandleException(e);
            }
        }
Ejemplo n.º 11
0
        public static void XPOStart()
        {
            try
            {
                string conString = SQLiteConnectionProvider.GetConnectionString(string.Format("{0}\\projects.ldb", System.Windows.Forms.Application.StartupPath));
                DevExpress.Xpo.Metadata.XPDictionary dictionary = new DevExpress.Xpo.Metadata.ReflectionDictionary();
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(conString, AutoCreateOption.DatabaseAndSchema);
                DevExpress.Xpo.XpoDefault.Session = new DevExpress.Xpo.Session(XpoDefault.DataLayer);
                //DevExpress.Xpo.Helpers.SessionStateStack.SuppressCrossThreadFailuresDetection = true;
                //DevExpress.Xpo.Session.DefaultSession.UpdateSchema();

                //IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);
                //var layer = new ThreadSafeDataLayer(dictionary, store);
            }
            catch (Exception ex)
            {
                Utility.Hata(ex);
            }
        }
Ejemplo n.º 12
0
        protected override void OnSetupStarted()
        {
            base.OnSetupStarted();
#if DEBUG
            var dirName = Path.GetDirectoryName(GetType().Assembly.Location);
            var dbName  = $"{nameof(FeatureCenterBlazorApplication)}.db";

            var dbPath = string.IsNullOrEmpty(dirName)
                ? dbName
                : Path.Combine(dirName, dbName);

            ConnectionString = SQLiteConnectionProvider.GetConnectionString(dbPath);
#else
            var configuration = ServiceProvider.GetRequiredService <IConfiguration>();
            if (configuration.GetConnectionString("DefaultConnection") != null)
            {
                ConnectionString = configuration.GetConnectionString("DefaultConnection");
            }
#endif
        }
Ejemplo n.º 13
0
        public static Session GetSessionThreadSafeDataLayer(string connectionString = null)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                var fullPathDataBase = Path.GetFullPath(StringSQLiteConnection);
                connectionString = SQLiteConnectionProvider.GetConnectionString(fullPathDataBase);
            }

            var xpoTypeInfoSource  = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary;
            var connectionProvider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);

            var dl      = new ThreadSafeDataLayer(xpoTypeInfoSource, connectionProvider);
            var session = new Session(dl, null)
            {
                LockingOption = LockingOption.None,
                TrackPropertiesModifications = true
            };

            return(session);
        }
Ejemplo n.º 14
0
        private static void NewMethod()
        {
            // Retrieve the Data Store specific connection string.
            string connectionString  = MSSqlConnectionProvider.GetConnectionString(@"DBSRV\QWERTY", @"user02", @"8a0IucJ@Nx1Qy5HfFrX0Ob3m", @"Sales");
            string connectionString1 = SQLiteConnectionProvider.GetConnectionString(@"D:\TEMP\SQLite\SQLITEDB1.db3");
            //
            IDataLayer dataLayer = XpoDefault.GetDataLayer(connectionString1, AutoCreateOption.DatabaseAndSchema);

            XpoDefault.DataLayer = dataLayer;
            Session session = new Session();
            //
            XPCollection collection = new XPCollection(typeof(DataStoreModel));

            //
            DataStoreModel ds = new DataStoreModel();

            ds.Name             = "alex";
            ds.SyntaxProvider   = "Oracle 12";
            ds.ConnectionString = "#$%^";
            ds.Save();
        }
Ejemplo n.º 15
0
        public App()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            // Connect to SQLite
            var    filePath         = Path.Combine(documentsPath, "xpoXamarinDemo.db");
            string connectionString = SQLiteConnectionProvider.GetConnectionString(filePath) + ";Cache=Shared;";

            XpoHelper.InitXpo(connectionString);

            if (Device.RuntimePlatform == Device.iOS)
            {
                MainPage = new MainPage();
            }
            else
            {
                MainPage = new NavigationPage(new MainPage());
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DevExpress.Xpo.ConsoleCoreDemo");

            if (!Directory.Exists(appDataPath))
            {
                Directory.CreateDirectory(appDataPath);
            }
            // XPO data layer setup against a local SQLite database. Learn more at https://documentation.devexpress.com/CoreLibraries/2020/DevExpress-ORM-Tool/Feature-Center/Connecting-to-a-Data-Store.
            string connectionString = SQLiteConnectionProvider.GetConnectionString(Path.Combine(appDataPath, "myXpoApp.db"));

            XpoDefault.DataLayer = XpoDefault.GetDataLayer(connectionString, AutoCreateOption.DatabaseAndSchema);
            XpoDefault.Session   = null;

            try {
                Console.WriteLine();
                Console.WriteLine(" ***************************************************************************************************************|");
                Console.WriteLine("                                         XPO console demo application 1.0");
                Console.WriteLine("     Uses eXpressPersistent Objects (XPO) for .NET Standard 2.0 - Object-Relational Mapping for .NET Developers");
                Console.WriteLine("     and Microsoft.Data.Sqlite 2.0 - ADO.NET provider for SQLite database");
                Console.WriteLine(" ***************************************************************************************************************|");
                while (true)
                {
                    Console.WriteLine();
                    Console.WriteLine("- Enter some text to create a new record.");
                    Console.WriteLine("- Say \"show\" to display stored records.");
                    Console.WriteLine("- Say \"clear\" to delete all records.");
                    Console.WriteLine("- Say \"xpo\" to learn more.");
                    Console.WriteLine("- Say \"quit\" for exit.");
                    Console.WriteLine();
                    Console.Write("XPO > ");
                    string result = Console.ReadLine();
                    switch (result.ToLowerInvariant())
                    {
                    case "show":
                        Console.WriteLine();
                        Console.WriteLine("|-------------------- start --------------------|");
                        using (UnitOfWork uow = new UnitOfWork()) {
                            var query = uow.Query <StatisticInfo>()
                                        .OrderBy(info => info.Date)
                                        .Select(info => $"[{info.Date}] {info.Info}");
                            foreach (var line in query)
                            {
                                Console.WriteLine(line);
                            }
                        }
                        Console.WriteLine("|--------------------  end  --------------------|");
                        Console.WriteLine();
                        break;

                    case "clear":
                        // Querying and deleting XPO objects. Learn more at https://documentation.devexpress.com/CoreLibraries/2026/DevExpress-ORM-Tool/Feature-Center/Data-Exchange-and-Manipulation/Deleting-Persistent-Objects.
                        using (UnitOfWork uow = new UnitOfWork()) {
                            var itemsToDelete = uow.Query <StatisticInfo>().ToList();
                            if (itemsToDelete.Count > 0)
                            {
                                var pluralEnding = itemsToDelete.Count > 1 ? "s" : "";
                                Console.Write($"Are you sure you want to delete {itemsToDelete.Count} record{pluralEnding} (y/N)?: ");
                                if (Console.ReadLine().ToLowerInvariant() == "y")
                                {
                                    uow.Delete(itemsToDelete);
                                    uow.CommitChanges();
                                    Console.WriteLine($"Done.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("There are no records to delete.");
                            }
                        }
                        break;

                    case "exit":
                    case "quit":
                        return;

                    case "xpo": {
                        Console.WriteLine("Starting browser...");
                    }
                    break;

                    default:
                        // Creating and saving a new XPO object. Learn more at https://documentation.devexpress.com/CoreLibraries/2023/DevExpress-ORM-Tool/Feature-Center/Data-Exchange-and-Manipulation.
                        using (UnitOfWork uow = new UnitOfWork()) {
                            StatisticInfo newInfo = new StatisticInfo(uow);
                            newInfo.Info = result;
                            newInfo.Date = DateTime.Now;
                            uow.CommitChanges();
                            Console.WriteLine("Saved.");
                        }
                        break;
                    }
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                Console.ReadKey();
            }
        }
Ejemplo n.º 17
0
        protected override async void OnInitialized()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            //MSSqlServer

            //string connectionString = MSSqlConnectionProvider.GetConnectionString("YOUR_SERVER_NAME", "sa", "", "XamarinDemo");

            //SQLite

            var    filePath         = Path.Combine(documentsPath, "xpoXamarinDemo.db");
            string connectionString = SQLiteConnectionProvider.GetConnectionString(filePath) + ";Cache=Shared;";

            //In-memory data store with saving/loading from the xml file

            //var filePath = Path.Combine(documentsPath, "xpoXamarinDemo.xml");
            //string connectionString = InMemoryDataStore.GetConnectionString(filePath);


            //DevExpress.Xpo.SimpleDataLayer.SuppressReentrancyAndThreadSafetyCheck = true;

            XPOWebApi.Register();

            connectionString = XPOWebApi.GetConnectionString("http://192.168.122.101/BitServer", string.Empty, "db1");


            XpoHelper.InitXpo(connectionString);



            using (var UoW = XpoHelper.CreateUnitOfWork())
            {
                if (UoW.Query <Contact>().Count() == 0)
                {
                    Contact Joche = new Contact(UoW)
                    {
                        Name = "Jose Manuel Ojeda Melgar", Phone = "+7897654321"
                    };
                    Contact Javier = new Contact(UoW)
                    {
                        Name = "Jose Javier Columbie", Phone = "+1897654321"
                    };
                    Contact Jaime = new Contact(UoW)
                    {
                        Name = "Jaime Macias", Phone = "+123423431"
                    };
                    Contact Rafael = new Contact(UoW)
                    {
                        Name = "Rafael Gonzales", Phone = "+14305345345"
                    };
                }

                if (UoW.InTransaction)
                {
                    UoW.CommitChanges();
                }
            }

            await NavigationService.NavigateAsync("NavigationPage/ContactList");
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Подключение к БД.
        /// </summary>
        private void Connect()
        {
            switch (DataBaseType)
            {
            case SQLType.Access:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.Access2007:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);

                    //string connctionString = string.Format(@"Data Source={0};Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=qwe+ASDFG", Server);
                    //XpoDefault.DataLayer = XpoDefault.GetDataLayer(connctionString, AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSqlCE:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MySQL:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    MySqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                    AutoCreateOption);
                break;

            case SQLType.Oracle:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.Firebird:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PostgreSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.SQLite:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.VistaDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PervasiveSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.DB2:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.NexusDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            default:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    AccessConnectionProvider.GetConnectionString(DataBase),
                    AutoCreateOption.DatabaseAndSchema);
                break;
            }
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.WriteLine("XPO Console Demo");

            XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                SQLiteConnectionProvider.GetConnectionString("console.db"),
                AutoCreateOption.DatabaseAndSchema);

            using (var uow = new UnitOfWork())
            {
                uow.ClearDatabase();
            }

            using (var uow = new UnitOfWork())
            {
                var order1 = new Order(uow)
                {
                    OrderNo   = 1,
                    OrderDate = DateTime.Now.AddDays(-5),
                    Client    = "Customer A"
                };
                order1.OrderItems.Add(new OrderItem(uow)
                {
                    Qty         = 1,
                    Description = "Product A",
                    UnitPrice   = 10
                });
                order1.OrderItems.Add(new OrderItem(uow)
                {
                    Qty         = 2,
                    Description = "Product B",
                    UnitPrice   = 15
                });
                new OrderItem(uow)
                {
                    Qty         = 2,
                    Description = "Product C",
                    UnitPrice   = 20,
                    Order       = order1
                };

                var order2 = new Order(uow)
                {
                    OrderNo   = 2,
                    OrderDate = DateTime.Now.AddDays(-40),
                    Client    = "Customer B"
                };
                order2.OrderItems.Add(new OrderItem(uow)
                {
                    Qty         = 1,
                    Description = "Product A",
                    UnitPrice   = 10
                });
                order2.OrderItems.Add(new OrderItem(uow)
                {
                    Qty         = 2,
                    Description = "Product D",
                    UnitPrice   = 15
                });

                uow.CommitChanges();
            }

            using (var uow = new UnitOfWork())
            {
                var orders = from o in uow.Query <Order>()
                             where o.OrderDate < DateTime.Now.AddDays(-10)
                             orderby o.OrderDate
                             select o;
                foreach (var o in orders)
                {
                    Console.WriteLine($"Order #{o.OrderNo} / {o.OrderDate}, client {o.Client}, Total Amount { o.TotalAmount }");
                    foreach (var i in o.OrderItems)
                    {
                        Console.WriteLine($"   {i.Qty} x {i.Description} ({i.UnitPrice}) = {i.Price}");
                    }
                }
            }
        }