Click here to Skip to main content
15,892,005 members
Articles / Desktop Programming / WPF

The WPF-NHibernate Toolkit

Rate me:
Please Sign up or sign in to vote.
4.98/5 (23 votes)
16 Jan 2010CPOL28 min read 159.7K   3.3K   114  
Adapt NHibernate classes to run in WPF
using System;
using System.Collections.Generic;
using System.Windows;
using VmWrapperDemo.Domain;
using VmWrapperDemo.View;
using VmWrapperDemo.ViewModel;

namespace VmWrapperDemo
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            /* We don't want to clutter up the demo with NHibernate code, so we
             * manually create the same type of collections that NHibernate would
             * return to us if we were reading from a database. */

            // Create domain model 
            IList<Customer> customers = new List<Customer>();
            var newCustomer = new Customer("Doe Shipping, Inc.", "John Doe");
            newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 01), 1000));
            newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 15), 750));
            customers.Add(newCustomer);

            newCustomer = new Customer("Roe Salvage, Inc.", "Larry Roe");
            newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 08), 2000));
            newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 22), 1500));
            customers.Add(newCustomer);

            // Create view model
            var mainWindowViewModel = new MainWindowViewModel(customers);

            // Initialize main window
            var mainWindow = new WindowMain();
            mainWindow.DataContext = mainWindowViewModel;
            mainWindow.Show();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Foresight Systems
United States United States
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.

Comments and Discussions