/// <summary> /// Opens the file. /// </summary> private void OpenFile() { bool createSchema = false; if (!File.Exists(Filename)) { createSchema = true; SqlCeEngine engine = new SqlCeEngine(SqlCE.GetConnectionString(Filename)); engine.CreateDatabase(); engine.Dispose(); } if (!SqlCeTicketDataSource.ActiveRecordsInitialized) { IDictionary <string, string> properties = new Dictionary <string, string>(); properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver"); properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect"); properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); properties.Add("connection.connection_string", SqlCE.GetConnectionString(Filename)); properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); InPlaceConfigurationSource source = new InPlaceConfigurationSource(); source.Add(typeof(ActiveRecordBase), properties); ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source); SqlCeTicketDataSource.ActiveRecordsInitialized = true; } else { SqlCeConnection con = new SqlCeConnection(SqlCE.GetConnectionString(Filename)); con.Open(); DifferentDatabaseScope scope = new DifferentDatabaseScope(con); } if (createSchema) { ActiveRecordStarter.CreateSchema(); } AllTickets = new ObservableCollection <ITicket>(); IQueryable <ITicket> list = (from t in TicketRecord.Queryable select t).Cast <ITicket>(); list.ToList().ForEach((Action <ITicket>) delegate(ITicket t) { t.PropertyChanged += new PropertyChangedEventHandler(ticket_PropertyChanged); AllTickets.Add(t); }); AllTickets.CollectionChanged += new NotifyCollectionChangedEventHandler(Tickets_CollectionChanged); UpdateActiveTickets(); }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { InitializeIfNecessary(); ISessionScope scope; if (maybeUserProvidedConnection == null) { scope = new SessionScope(FlushAction.Never); } else { scope = new DifferentDatabaseScope(maybeUserProvidedConnection); } return(new ActiveRecordUnitOfWorkAdapter(scope, previous)); }