Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var nemoConfig = ConfigurationFactory.CloneCurrentConfiguration();

            nemoConfig.SetDefaultCacheRepresentation(Nemo.CacheRepresentation.None).SetLogProvider(new Logger()).SetLogging(true).SetAutoTypeCoercion(true);

            ObjectContainer.Current.Register <ITestRepo>(() => new TestRepo(new Yarn.Data.NemoProvider.RepositoryOptions {
                UseStoredProcedures = false, Configuration = nemoConfig
            }, new Yarn.Data.NemoProvider.DataContextOptions {
                ConnectionName = "ExcitContext"
            }), "Nemo");

            var repo = ObjectContainer.Current.Resolve <ITestRepo>("Nemo");

            var loadedTestModel = repo.LoaderGetDataStoreAsync(166).ToList();

            var getDataStoreByIdQuery = new GetDataStoreById(166);
            var queryResult           = getDataStoreByIdQuery.Execute(repo);

            var getDataStoreByIdQueryWithPrices = new GetDataStoreByIdWithPrices(166);
            var queryResultWithPrices           = getDataStoreByIdQueryWithPrices.Execute(repo).Items;

            //var testModel1 = (await repo.GetDataStoreAsync()).ToList();
            //var testModel2 = (await repo.GetInstanceStoreAsync()).ToList();
        }
Exemplo n.º 2
0
        protected void SetConfiguration(Type type)
        {
            if (_configured.Contains(type))
            {
                return;
            }

            if (_options == null)
            {
                _configured.Add(type);
                return;
            }

            if (!_options.UseStoredProcedures && _options.Configuration != null)
            {
                _options.Configuration.SetGenerateDeleteSql(true).SetGenerateInsertSql(true).SetGenerateUpdateSql(true);
                ConfigurationFactory.Set(type, _options.Configuration);
            }
            else if (!_options.UseStoredProcedures)
            {
                var config = _options.Configuration ?? ConfigurationFactory.Get(type);
                if (config == ConfigurationFactory.DefaultConfiguration)
                {
                    config = ConfigurationFactory.CloneCurrentConfiguration().SetGenerateDeleteSql(true).SetGenerateInsertSql(true).SetGenerateUpdateSql(true);
                    ConfigurationFactory.Set(type, config);
                }
                else
                {
                    config.SetGenerateDeleteSql(true).SetGenerateInsertSql(true).SetGenerateUpdateSql(true);
                }
            }
            else if (_options.Configuration != null)
            {
                ConfigurationFactory.Set(type, _options.Configuration);
            }
            _configured.Add(type);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var nemoConfig = ConfigurationFactory.CloneCurrentConfiguration();

            nemoConfig.SetDefaultCacheRepresentation(Nemo.CacheRepresentation.None).SetAutoTypeCoercion(true);

            ObjectContainer.Current.Register <IRepository>(() => new Yarn.Data.NemoProvider.Repository(new Yarn.Data.NemoProvider.RepositoryOptions {
                UseStoredProcedures = false, Configuration = nemoConfig
            }, new Yarn.Data.NemoProvider.DataContextOptions {
                ConnectionName = "Yarn.EF2.Connection"
            }), "Nemo");

            ObjectContainer.Current.Register <IRepository>(() => new Yarn.Data.EntityFrameworkProvider.Repository(new Yarn.Data.EntityFrameworkProvider.DataContextOptions {
                LazyLoadingEnabled = false, ProxyCreationEnabled = false, NameOrConnectionString = "Yarn.EF2.Connection", ConfigurationAssembly = typeof(Program).Assembly
            }), "EF");

            ObjectContainer.Current.Register <IRepository>(() => new Yarn.Data.EntityFrameworkProvider.Repository(new Yarn.Data.EntityFrameworkProvider.DataContextOptions {
                LazyLoadingEnabled = false, ProxyCreationEnabled = false, DbContextType = typeof(NorthwindEntities)
            }), "EF2");

            ObjectContainer.Current.Register <IRepository>(() => new Yarn.Data.EntityFrameworkCoreProvider.Repository(new Yarn.Data.EntityFrameworkCoreProvider.DataContext(new NorthwindEntitiesCore())), "EFCore");

            ObjectContainer.Current.Register <IRepository>(() => new Yarn.Data.InMemoryProvider.Repository(), "InMemory");

            var repo = ObjectContainer.Current.Resolve <IRepository>("EF");

            if (repo == null)
            {
                Console.WriteLine("RepoNull");
            }
            var dctx = repo.DataContext;

            if (dctx == null)
            {
                Console.WriteLine("UoWNull");
            }
            else
            {
                //var context = dctx as IDataContext<Microsoft.EntityFrameworkCore.DbContext>;
                var context = dctx as IDataContext <DbContext>;
                if (context != null)
                {
                    var session   = context.Session;
                    var tableName = session.GetTableName <Customer>();
                }
                //repo.As<IBulkOperationsProvider>().Update<Customer>(c => c.CustomerID.Length > 12, c => new Customer { ContactName = c.ContactName + " 2" });
                //repo.As<IBulkOperationsProvider>().Delete<Customer>(c => c.CustomerID.Length > 12, c => c.CustomerID.StartsWith("AL"));
            }

            //var customer = repo.GetById<Customer, string>("ALFKI");

            Customer eagerCustomer = null;
            var      loader        = repo.As <ILoadServiceProvider>();

            if (loader != null)
            {
                eagerCustomer = loader.Load <Customer>().Include(c => c.Orders).Include(c => c.Orders.Select(o => o.Order_Details)).Find(c => c.CustomerID == "ALFKI");
            }

            var customersFromLondon = repo.FindAll <Customer>(c => c.City == "London", offset: 1).ToList();

            var customers = repo.Execute <Customer>("EXEC spDTO_Customer_Retrieve @CustomerID", new ParamList {
                { "CustomerID", "ALFKI" }
            });

            var cachedRepo = repo.WithCache <LocalCache>();
            var id         = "ALFKI";
            var customer1  = cachedRepo.Find <Customer>(c => c.CustomerID == id);
            var customer2  = cachedRepo.Find <Customer>(c => c.CustomerID == id);

            if (ReferenceEquals(customer1, customer2))
            {
                Console.WriteLine("From Cache");
            }
            else
            {
                Console.WriteLine("Not From Cache");
            }

            var query  = new GetCustomerByIdQuery("ANATR");
            var result = query.Execute(repo);

            var customerRepo = new CustomerRepository(repo);
            var customer     = customerRepo.GetById("ANTON");
        }