public override List <SystemItem> AvailableItems <T>(ItemIdentifier itemId) { //if looking for children, return nothing if (itemId != null) { return(new List <SystemItem>()); } List <SystemItem> allItems = new List <SystemItem>(); var session = NHibernateProvider.GetCurrentSession(); foreach (var c in session.Linq <CompanyProxy>()) { SystemItem si = new SystemItem(); si.Description = "Company with the name: " + c.Name; si.Name = c.Name; si.ItemId = new ItemIdentifier(c.Symbol, Constants.companyProviderID); si.Icon = "package2.png"; si.HasChildren = false; allItems.Add(si); } return(allItems); }
public void Install(IWindsorContainer container, IConfigurationStore store) { NHibernateProvider provider = new NHibernateProvider(_connectionString); //Registering Services container.Register(Component.For(typeof(IGenericService <CaseDTO>)).ImplementedBy(typeof(GenericService <CaseDTO, Case>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IProductService <CaseDTO>)).ImplementedBy(typeof(ProductService <CaseDTO, Case>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <CoolerDTO>)).ImplementedBy(typeof(GenericService <CoolerDTO, Cooler>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <CPUDTO>)).ImplementedBy(typeof(GenericService <CPUDTO, CPU>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <DesktopDTO>)).ImplementedBy(typeof(GenericService <DesktopDTO, Desktop>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <DiskDTO>)).ImplementedBy(typeof(GenericService <DiskDTO, Disk>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <DisplayDTO>)).ImplementedBy(typeof(GenericService <DisplayDTO, Display>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <GPUDTO>)).ImplementedBy(typeof(GenericService <GPUDTO, GPU>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <HeadphonesDTO>)).ImplementedBy(typeof(GenericService <HeadphonesDTO, Headphones>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <KeyboardDTO>)).ImplementedBy(typeof(GenericService <KeyboardDTO, Keyboard>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <LaptopDTO>)).ImplementedBy(typeof(GenericService <LaptopDTO, Laptop>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <MonitorDTO>)).ImplementedBy(typeof(GenericService <MonitorDTO, Monitor>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <MotherboardDTO>)).ImplementedBy(typeof(GenericService <MotherboardDTO, Motherboard>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <MouseDTO>)).ImplementedBy(typeof(GenericService <MouseDTO, Mouse>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <PowerUnitDTO>)).ImplementedBy(typeof(GenericService <PowerUnitDTO, PowerUnit>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <RAMDTO>)).ImplementedBy(typeof(GenericService <RAMDTO, RAM>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IGenericService <SpeakersDTO>)).ImplementedBy(typeof(GenericService <SpeakersDTO, Speakers>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IUserService)).ImplementedBy(typeof(UserService)).LifestylePerWebRequest()); //container.Register(Component.For(typeof(IWarehouseProductService)).ImplementedBy(typeof(WarehouseProductService)).LifestylePerWebRequest()); //Registering Repositories container.Register(Component.For(typeof(IGenericRepository <>)).ImplementedBy(typeof(GenericRepository <>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IProductRepository <>)).ImplementedBy(typeof(ProductRepository <>)).LifestylePerWebRequest()); container.Register(Component.For(typeof(IUserRepository)).ImplementedBy(typeof(UserRepository)).LifestylePerWebRequest()); //container.Register(Component.For(typeof(IWarehouseProductRepository)).ImplementedBy(typeof(WarehouseProductRepository)).LifestylePerWebRequest()); //Registering Default NHibernate Interfaces container.Register(Component.For <ISessionFactory>().Instance(provider.SessionFactory).LifestyleSingleton()); container.Register(Component.For <ISession>().UsingFactory((ISessionFactory sessionFactory) => sessionFactory.OpenSession()).LifestylePerWebRequest()); container.Register(Component.For <ITransaction>().UsingFactory((ISession session) => session.BeginTransaction()).LifestylePerWebRequest()); }
public void FixtureSetup() { var provider = new NHibernateProvider(); _config = provider.CreateConfiguration(); _sessionFactory = provider.CreateSessionFactory(_config); _session = _sessionFactory.OpenSession(); provider.ExportSchema(_config, _session.Connection); using (var trans = _session.BeginTransaction()) { var modelCreator = new NHibernateQueryingModel(); modelCreator.CreateModel(_session); trans.Commit(); } _query = new QueryAdapter(_session); QueryableExtensions.EagerFetchingProvider = new EagerFetchingProvider(); QueryableExtensions.LazyQueryingProvider = new LazyResultProvider(); QueryableExtensions.AsyncQueryingProvider = new AsyncQueryProvider(); }
public void NHibernateProviderTest() { var provider = new NHibernateProvider(@"A:\CodeSmith\CodeSmith.googlecode.framework.samples\PLINQO-NH\CSharp\Tracker\Data\Maps\"); var manager = new EntityManager(provider); Assert.Greater(manager.Entities.Count(), 0); }
private NHibernateExecutionBlock() { INHibernateProvider nhibernateProvider = new NHibernateProvider(); IGlimpseDbDriverFactory glimpseDbDriverFactory = new GlimpseDbDriverFactory(); IGlimpseDbDriverActivator glimpseDbDriverActivator = new GlimpseDbDriverActivator(); RegisterProvider(new NHibernateDbDriverWrapperExecutionTask(Logger, nhibernateProvider, glimpseDbDriverFactory, glimpseDbDriverActivator)); }
private static void CreateNewCountry(Country country) { using (var session = NHibernateProvider.GetSession()) { using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(country); transaction.Commit(); } } }
public static IList <Country> GetAllCountries() { using (var session = NHibernateProvider.GetSession()) { using (var transaction = session.BeginTransaction()) { var countries = session.QueryOver <Country>() .List <Country>(); return(countries); } } }
private static Country GetCountryByAlpha2Code(string alphaCode) { using (var session = NHibernateProvider.GetSession()) { using (var transaction = session.BeginTransaction()) { var country = session.QueryOver <Country>() .Where(x => x.Alpha2Code == alphaCode) .SingleOrDefault(); return(country); } } }
public NHibernateTest() { _settings = new AdapterSettings(); _baseDirectory = Directory.GetCurrentDirectory(); _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.LastIndexOf("\\Bin")); _settings["BaseDirectoryPath"] = _baseDirectory; Directory.SetCurrentDirectory(_baseDirectory); _settings.AppendSettings(new StaticDust.Configuration.AppSettingsReader("App.config")); _settings["ProjectName"] = "12345_000"; _settings["ApplicationName"] = "ABC"; _settings["SchemaObjectName"] = "LINES"; _settings["ExecutingAssemblyName"] = "NUnit.Tests"; _hibernateProvider = new NHibernateProvider(_settings); }
public override T PersistItem <T>(T item) { var session = NHibernateProvider.GetCurrentSession(); Company update = item as Company; CompanyProxy current = GetCompanyBySymbol(update.Symbol, session); //if it doesn exist if (current == null) { session.Save(ParseToProxy(update)); } else { //set the ID to the current one and persist in case company had its other values updated update.Id = current.Id; session.Update(ParseToProxy(update)); } return(update as T); }
private static void DeleteCountryByAlphaCode(string alphaCode) { using (var session = NHibernateProvider.GetSession()) { using (var transaction = session.BeginTransaction()) { var country = session.QueryOver <Country>() .Where(x => x.Alpha2Code == alphaCode) .SingleOrDefault <Country>(); try { session.Delete(country); transaction.Commit(); } catch (ArgumentNullException e) { Console.WriteLine(e.Message); } } } }
public override T RetrieveItem <T>(ItemIdentifier itemId) { var session = NHibernateProvider.GetCurrentSession(); //here we allow 2 ways to get it, either by ID, or by symbol //this way we don't need to do alot of conversion of id -> symbol int companyId = 0; string companySymbol = itemId.Id; //the item proxy returned from nhibernate CompanyProxy retval; if (int.TryParse(itemId.Id, out companyId)) { //return based on ID retval = session.Get <CompanyProxy>(companyId); } else { //return based on symbol retval = GetCompanyBySymbol(companySymbol, session); } //if not found, return null if (retval == null) { return(null); } Company c = ParseFromProxy(retval); //set the item ID to the Symbol and the provider ID c.ItemId = new ItemIdentifier(retval.Symbol, itemId.ProviderId); //cast as T return(c as T); }
public void It_should_wrap_all_drivers() { var logger = new Mock <ILogger>(); var nhibernateProvider = new NHibernateProvider(); var glimpseDbDriverFactory = new GlimpseDbDriverFactory(); var glimpseDbDriverActivator = new GlimpseDbDriverActivator(); var nhibernateDbDriverWrapperExecutionTask = new NHibernateDbDriverWrapperExecutionTask(logger.Object, nhibernateProvider, glimpseDbDriverFactory, glimpseDbDriverActivator); BuildSessionFactory(); // Act nhibernateDbDriverWrapperExecutionTask.Execute(); // Assert var nhibernateDriverInfos = nhibernateProvider.GetNHibernateDriverInfos().ToList(); Assert.Equal(1, nhibernateDriverInfos.Count()); foreach (var nhibernateDriverInfo in nhibernateDriverInfos) { Assert.True(nhibernateDriverInfo.IsWrapped()); } }
static void Main(string[] args) { //App_Start.NHibernateProfilerBootstrapper.PreStart(); #region countries //var moldova = new Country("Moldova", 648, "MD"); //var italia = new Country("Italia", 040, "IT"); //var ucraina = new Country("Ucraina", 854, "UA"); //var russia = new Country("Russia", 643, "RU"); //var countries = new List<Country>() { moldova, italia, ucraina, russia }; #endregion #region Location //Location locChisinau = new Location(new City("Chisinau", moldova), new AddressDetail("2048", "str. Stefan cel mare 34")); //Location locBardar = new Location(new Village("Bardar", moldova), new AddressDetail("2048", "no street")); //Location locMoscow = new Location(new City("Moscow", russia)); //Location locRome = new Location(new Village("Padovana", italia)); //Location locKiev = new Location( locality: new City("Kiev", ucraina)); #endregion #region PostData //// posting new information about Transport Freight //var post1 = new PostCargo(new DateTime(2017, 7, 07), new DateTime(2017, 7, 09), locMoscow, locRome, 2450.00, "call 379166741"); //var post2 = new PostCargo(new DateTime(2017, 7, 07), new DateTime(2017, 7, 09), locMoscow, locRome, 3875.00, "call 379166741"); //var post3 = new PostTransport(new DateTime(2017, 7, 10), new DateTime(2017, 7, 12), locKiev, locChisinau, 4100.00, "call 379166741"); //var post4 = new PostCargo(new DateTime(2017, 7, 14), new DateTime(2017, 7, 12), locKiev, locBardar, 3800.00, "call 379166741"); //// named arg //var post5 = new PostCargo(locationFrom: locChisinau, locationTo: locKiev, // dataFrom: new DateTime(2017, 07, 20), dateTo: new DateTime(2017, 08, 02), price: 3500.00, additionalInformation: "call 379166741"); #endregion #region Comparer //// ex. IEqualityComparer //var dict = new Dictionary<Country, string>(new CountryEqalityComparer()); //// ex. Icomparer //countries.Sort(new CountryComparer()); #endregion #region EVENTS //// new users //User user1 = new User("Stipanov", "Sergiu", 35); //User user2 = new User("Maracuta", "Andrei", 27); //// subscribe to event price rice //user1.RegisterToEvent(post1); //user2.RegisterToEvent(post1); //// Register weak events by WeakEventManager //user1.RegisterToEventWeakMethod(post2); //user1.RegisterToEventWeakMethod(post3); //// simulate change price //post1.Price = 3750; //post2.Price = 2550; //Console.WriteLine(); //// UnregisterToEvent //user2.UnregisterToEvent(post1); //user1.UnregisterToEventWeakMethod(post3); //// simulate change price //post1.Price = 3800; #endregion #region Stream //string fileName = @"C:\Users\sergiu.stipanov\OneDrive\Materiale\files\Repository.txt"; //FileInfo f = new FileInfo(fileName); //StreamWriter sr = f.AppendText(); //sr.WriteLine("hello"); //sr.Close(); //Console.WriteLine(sr); //Console.WriteLine(); ////save countries to file //Repository<Country> countryRepository = new Repository<Country>(); //foreach (var c in countries) //{ // countryRepository.SaveToFile(c, fileName); //} #endregion #region FACTORY //PostFactory postFactory = new PostFactory(); //var beerCargoSpecification = new CargoSpecification("Karlsberg Beer", 7.5, 3.7); //var woodCargoSpecification = new CargoSpecification("Wood", 15.45, 27.00); //var truckSpecification = new TransportSpecification(PostTransportType.Truck, 20.00, 35.00); //var minibusSpecification = new TransportSpecification(PostTransportType.Minibus, 6.00, 7.8); //var newPostCargo = postFactory.CreateNewPost( // new DateTime(2017, 07, 25), new DateTime(2017, 08, 05), locRome, // locChisinau, 4750.00, "Call 373 6544518", beerCargoSpecification); //Console.WriteLine(newPostCargo.ToString()); //WriteLine(newPostCargo is PostCargo); //var newPostTransport = postFactory.CreateNewPost(new DateTime(2017, 07, 08), new DateTime(2017, 08, 31), locMoscow, // locChisinau, 1875.00, "For more information Call +3739547821", truckSpecification); //Console.WriteLine(newPostTransport); //Console.WriteLine(newPostTransport is PostCargo); #endregion #region NHIBERNATE NHibernateProfiler.Initialize(); #region CRUD //var countries = GetAllCountries(); //var nedederlada = GetCountryByAlpha2Code("NL"); //CreateNewCountry(new Country ( "Spain", 724, "ES")); //CreateNewCountry(new Country("ESTONIA", 233, "EE")); //CreateNewCountry(new Country("LUXEMBOURG", 442, "LU")); //CreateNewCountry(new Country("NETHERLANDS", 528, "NL")); //CreateNewCity(new City("Barcelona", GetCountryByAlpha2Code("ES"))); //CreateNewCity(new City("Madrid", GetCountryByAlpha2Code("ES"))); //DeleteCountryByAlphaCode("ES"); //var amsterdam = new City("Amsterdam"); #endregion #region QueryOver //using (var session = NHibernateProvider.GetSession()) //{ // using (var transaction = session.BeginTransaction()) // { // //var countries = session.QueryOver<Country>() // // .Where(c => c.Alpha2Code == "RO") // // .Select(c => c.Name) // // .SingleOrDefault<string>(); // //var countries = session.QueryOver<Country>() // // .Where(c => c.Alpha2Code == "RO") // // .Select(c => c.NumericCode) // // .SingleOrDefault<int>(); // //var countries = session.QueryOver<Country>() // // .Where(c => c.Alpha2Code == "IT") // // .SelectList(list => list // // .Select(c => c.Name) // // .Select(c => c.Alpha2Code) // // .Select(x => x.NumericCode)) // // .List<object[]>(); // //Country country = null; // //var country_projection = session.QueryOver(() => country) // // .Select(Projections.ProjectionList() // // .Add(Projections.Property(() => country.Name)) // // .Add(Projections.Property(() => country.NumericCode))) // // .List<object[]>(); // //City city = null; // //var city_projection = session.QueryOver(() => city) // // .Select(Projections.ProjectionList() // // .Add(Projections.Property(() => city.Name)) // // .Add(Projections.Property(() => city.Country.Id))) // // .List<object[]>(); // //Country country = null; // //City city = null; // //var query = session.QueryOver(() => country) // // .JoinAlias(c => c.Localities, () => city) // // .List<Country>(); // //Country country = null; // //City city = null; // //var query = session.QueryOver(() => country) // // .JoinAlias(c => c.Localities, () => city) // // .TransformUsing(Transformers.DistinctRootEntity) // // .List<Country>(); // //Country country = null; // //City city = null; // //Location location = null; // //var query = session.QueryOver(() => location) // // .JoinQueryOver(l => l.Locality, () => city) // // .JoinQueryOver(c => c.Country, () => country) // // .List(); // //Country country = null; // //City city = null; // //Location location = null; // //var query = session.QueryOver(() => location) // // .JoinAlias(l => l.Locality, () => city) // // .JoinAlias(() => city.Country, () => country) // // .List(); // //Country country = null; // //City city = null; // //Location location = null; // //var LocalityFromMoldova = session.QueryOver(() => location) // // .JoinAlias(l => l.Locality, () => city) // // .JoinAlias(() => city.Country, () => country) // // .Where(() => country.Alpha2Code == "MD" ) // // .SelectList(list => list // // .Select(() => country.Name) // // .Select(() => city.Name) // // .Select(x => x.Line1)) // // .List<object[]>(); // // group // //City city = null; // //Location location = null; // //// Cite adresse concerete am in fiecare City // //var group = session.QueryOver(() => location) // // .JoinAlias(() => location.Locality, () => city) // // .SelectList(list => list // // .SelectGroup(() => city.Name) // // .SelectCount(() => city.Id)) // // .List<object[]>(); // //// Having // //City city = null; // //Location location = null; // //// mai mult de 2 adresse concerete in fiecare City // //var group = session.QueryOver(() => location) // // .JoinAlias(() => location.Locality, () => city) // // .SelectList(list => list // // .SelectGroup(() => city.Name) // // .SelectCount(() => city.Id)) // // .Where(Restrictions.Gt(Projections.Count(Projections.Property(() => city.Id)), 2)) // // .List<object[]>(); // // AliasToBean // // Returnam detaile la PostCargo // //PostCargo post = null; // //Locality cityFrom = null; // //Locality cityTo = null; // //Location locationFrom = null; // //Location locationTo = null; // //Country countryFrom = null; // //Country countryTo = null; // //PostDetailRow postDetailRow = null; // //IList<PostDetailRow> query = session.QueryOver(() => post) // // .JoinAlias(p => p.LocationFrom, () => locationFrom) // // .JoinAlias(() => post.LocationTo, () => locationTo) // // .JoinAlias(() => locationFrom.Locality, () => cityFrom) // // .JoinAlias(() => locationTo.Locality, () => cityTo) // // .JoinAlias(() => cityFrom.Country, () => countryFrom) // // .JoinAlias(() => cityTo.Country, () => countryTo) // // .SelectList(list => list // // .Select(() => post.DateFrom).WithAlias(() => postDetailRow.DateFrom) // // .Select(() => post.DateTo).WithAlias(() => postDetailRow.DateTo) // // .Select(() => countryFrom.Name).WithAlias(() => postDetailRow.CountryFrom) // // .Select(() => cityFrom.Name).WithAlias(() => postDetailRow.CityFrom) // // .Select(() => countryTo.Name).WithAlias(() => postDetailRow.CountryTo) // // .Select(() => cityTo.Name).WithAlias(() => postDetailRow.CityTo) // // .Select(x => x.Price).WithAlias(() => postDetailRow.Price)) // // .TransformUsing(Transformers.AliasToBean<PostDetailRow>()) // // .List<PostDetailRow>(); // // DistinctRootEntity (fara distinct aveam 12, cu am 5, In SQL Distinc nu apare) // //Country country = null; // //City city = null; // //var query = session.QueryOver(() => country) // // .JoinAlias(c => c.Localities, () => city) // // .Where(() => country.NumericCode < 650) // // .TransformUsing(Transformers.DistinctRootEntity) // // .List<Country>(); // //// Future , FutureValue ////IEnumerable<Country> countries = session.QueryOver<Country>() //// .Future<Country>(); ////IFutureValue<int> numberOffCitys = session.QueryOver<City>() //// .SelectList(list => list //// .SelectCount(x => x.Id)) //// .FutureValue<int>(); ////int numCity = numberOffCitys.Value; // } // Console.WriteLine("Ok"); //} #endregion #region QueryOver Advanced using (var session = NHibernateProvider.GetSession()) { using (var transaction = session.BeginTransaction()) { // 1 //var countrySubquery = QueryOver.Of<Country>() // .Where(x => x.NumericCode > 458) // .Select(x => x.Id); //var query2 = session.QueryOver<City>() // .WithSubquery.WhereProperty(x => x.Country) // .In(countrySubquery) // .Select(x=> x.Name) // .List<string>(); // FindMostPopularCityInCountry , cel mai preferat loc de pornire Country country = null; Country innerCountry = null; City city = null; Locality place = null; Village village = null; PostCargo post = null; Location locationFrom = null; //// orasul cel mai des intilnit la plecare //var query1 = QueryOver.Of(() => post) // .JoinAlias(() => post.LocationFrom, () => locationFrom) // .JoinAlias(() => locationFrom.Locality, () => place) // .SelectList(list => list // .SelectGroup(() => place.Id) // .SelectCount(() => place.Id)) // .OrderBy(Projections.Count(() => place.Id)).Desc // .Take(1); /* * QueryOver.Of(() => post) * .JoinAlias(() => post.LocationFrom, () => locationFrom) * .JoinAlias(() => locationFrom.Locality, () => place) * .SelectList(list1 => list1 * .SelectCount(() => place.Country)) * .Where(Restrictions.EqProperty(Projections.Property(()=>place.Country.Id), * Projections.Property(()=>country.Id)))).WithAlias(() => obj) */ //// cite ori apare Country in postari //var subquery = QueryOver.Of(() => post) // .JoinAlias(() => post.LocationFrom, () => locationFrom) // .JoinAlias(() => locationFrom.Locality, () => place) // .SelectList(list1 => list1 // .SelectCount(() => place.Country)) // .Where(Restrictions.EqProperty(Projections.Property(() => place.Country.Id), // Projections.Property(() => country.Id))); //var query3 = session.QueryOver(() => country) // .SelectList(list => list // .Select(() => country.Name) // .Select(() => country.NumericCode) // .SelectSubQuery(subquery)) // .OrderBy(Projections.SubQuery(subquery)).Desc // .List<object>(); //Console.WriteLine("ok"); } Console.WriteLine("Ok hokey"); } #endregion var repository = new Repository <Country>(); repository.Dispose(); //var rominia = repository.GetById(2); //rominia.NumericCode = 777; //repository.Save(rominia); #endregion Console.ReadKey(); }
public NhCategoryDal(NHibernateProvider nHibernateProvider) : base(nHibernateProvider) { }
public CountryRepository() { _session = NHibernateProvider.GetSession(); }
public PostTransportRepository() { _session = NHibernateProvider.GetSession(); }
public PostCargoRepository() { _session = NHibernateProvider.GetSession(); }
public NhProductDal(NHibernateProvider nHibernateProvider) : base(nHibernateProvider) { _nHibernateProvider = nHibernateProvider; }
public HibernateService() { _NHibernateProvider = new NHibernateProvider(WebConfigurationManager.AppSettings); }
public LocalityRepository() { _session = NHibernateProvider.GetSession(); }