コード例 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // Specify where Entity Framework should look for the Northwind database.
            string folder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\..\..\..\Data"));
            string dbFile = Path.Combine(folder, "Northwnd.mdf");

            AppDomain.CurrentDomain.SetData("DataDirectory", folder);
            if (!File.Exists(dbFile))
            {
                throw new Exception("Sample database Northwnd.mdf must be created in the Data folder. Run the CreateSampleDB utility to create the Northwind database");
            }

            // make sure both version 11 and version 12 or higher of SQLServer LocalDb are supported
            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\12.0");
            string        ver     = key == null ? "v11.0" : "MSSQLLocalDB";
            Configuration config  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var           connStr = config.ConnectionStrings.ConnectionStrings["NORTHWNDEntities"];

            connStr.ConnectionString = connStr.ConnectionString.Replace("v11.0", ver);
            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("connectionStrings");

            base.OnStartup(e);

            // Get a global ClientCache and save it in a static field
            // so it is accessible from any class of the project.
            ClientCache = EntityClientCache.GetDefault(typeof(NORTHWNDEntities));
        }
コード例 #2
0
        static void Main()
        {
            // Specify where should Entity Framework look for the Northwind database.
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\ComponentOne Samples\Common";
            string dbFile = Path.Combine(folder, "Northwnd.mdf");

            AppDomain.CurrentDomain.SetData("DataDirectory", folder);
            if (!File.Exists(dbFile))
            {
                throw new Exception("Sample database Northwnd.mdf must be created in the Common folder. Run the CreateSampleDB utility to create the Northwind database");
            }

            // make sure both version 11 and version 12 or higher of SQLServer LocalDb are supported
            var config  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connStr = config.ConnectionStrings.ConnectionStrings["NORTHWNDEntities"];

            connStr.ConnectionString = connStr.ConnectionString.Replace("v11.0", GetLocalDBInstance());
            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("connectionStrings");

            // Get a global ClientCache and save it in a static field
            // so it is accessible from any class of the project.
            ClientCache = EntityClientCache.GetDefault(typeof(NORTHWNDEntities));

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: mdjabirov/C1Decompiled
        protected override void OnStartup(StartupEventArgs e)
        {
            // Specify where Entity Framework should look for the Northwind database.
            string folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
            string dbFile = Path.Combine(folder, "Northwnd.mdf");
            AppDomain.CurrentDomain.SetData("DataDirectory", folder);
            if (!File.Exists(dbFile))
                throw new Exception("Cannot find sample database Northwnd.mdf");

            base.OnStartup(e);

            // Get a global ClientCache and save it in a static field
            // so it is accessible from any class of the project.
            ClientCache = EntityClientCache.GetDefault(typeof(NORTHWNDEntities));
        }
コード例 #4
0
 public CustomerControl(Customer customer, EntityClientCache clientCache)
 {
     InitializeComponent();
     _cache   = clientCache;
     Customer = customer;
     // Define and bind a live view of orders of the customer.
     _ordersView = from o in customer.Orders.AsLive()
                   select new OrderInfo(o)
     {
         OrderID   = o.OrderID,
         OrderDate = o.OrderDate,
         Freight   = o.Freight,
         ShipName  = o.ShipName,
         ShipCity  = o.ShipCity
     };
     CreateTransaction();
     ordersGrid.ItemsSource = _ordersView;
 }
コード例 #5
0
        public MainWindow()
        {
            InitializeComponent();

            // Initialize the client cache and the client scope.
            _clientCache = new EntityClientCache(new NORTHWNDEntities());
            _scope       = new EntityClientScope(_clientCache);

            // Bind a combo box to the list of cities
            // using a live view of customers grouped by city.
            comboCity.ItemsSource =
                (from c in _scope.GetItems <Customer>()
                 group c by c.City into g
                 orderby g.Key
                 select new
            {
                City = g.Key,
                Customers = g
            }).AsDynamic();
        }
コード例 #6
0
ファイル: NORTHWNDContext.cs プロジェクト: hriess/WPFTutorial
 public NORTHWNDContext(EntityClientCache clientCache)
     : base(clientCache)
 {
 }