Example #1
0
        public static Solution PrepareSolution()
        {
            Solution solution = new Solution("SSAS_OLAP", "SSAS 测试");
            CubeEntity salesCube = new CubeEntity("SalesCube", "Sales");
            salesCube.TableName = "SaleHistory";
            solution.Cubes.Add(salesCube);

            var customerDim = new DimensionEntity("CustomerDim", "Customer") { FKColumn = "CustomerId" };
            customerDim.Levels.Add(new LevelEntity("customerlevel", "Customer") { SourceTable = "Customer", KeyColumn = "Id", NameColumn = "Name" });
            salesCube.Dimensions.Add(customerDim);

            var ProductDim = new DimensionEntity("ProductDim", "Product") { FKColumn = "ProductId" };
            ProductDim.Levels.Add(new LevelEntity("Productlevel", "Product") { SourceTable = "Product", KeyColumn = "Id", NameColumn = "Name" });
            salesCube.Dimensions.Add(ProductDim);

            //var DateDim = new SSASDim("DateDim");
            //DateDim.Levels = new List<ILevel>();
            //DateDim.Levels.Add(new Level("Datelevel", "Datelevel") { SourceTable = "" });
            //solution.Dims.Add(DateDim);

            salesCube.Measures.Add(new MeasureEntity("ProductCount", "ProductCount") { ColumnName = "ProductCount", Aggregator = Aggregator.Sum });
            salesCube.Measures.Add(new MeasureEntity("UnitPrice", "UnitPrice") { ColumnName = "UnitPrice", Aggregator = Aggregator.Sum });

            return solution;
        }
Example #2
0
        private void CreateDim(Database database, DataSourceView dataSourceView, DimensionEntity dim)
        {
            Dimension ssasDimension;
            if (!database.Dimensions.Contains(dim.ID))
            {
                ssasDimension = database.Dimensions.Add(dim.Name, dim.ID);
                ssasDimension.UnknownMember = UnknownMemberBehavior.Hidden;
                ssasDimension.AttributeAllMemberName = "all";
                ssasDimension.StorageMode = DimensionStorageMode.Molap;
                ssasDimension.Source = new DataSourceViewBinding(dataSourceView.ID);
                ssasDimension.Type = DimensionType.Regular;
            }
            else
            {
                ssasDimension = database.Dimensions[dim.ID];
            }
            if ((dim.Hierarchies == null || dim.Hierarchies.Count == 0) && (dim.Levels != null && dim.Levels.Count != 0))
            {
                if (!ssasDimension.Hierarchies.Contains(DefaultHierarchy))
                {
                    Hierarchy ssasHierarchy = ssasDimension.Hierarchies.Add(DefaultHierarchy, DefaultHierarchy);
                    ssasHierarchy.AllMemberName = "all";
                    CreateLevels(ssasDimension, ssasHierarchy, dataSourceView, dim.Levels);
                }
            }
            else
            {
                foreach (var outerHierarchy in dim.Hierarchies)
                {
                    Hierarchy ssasHierarchy;
                    if (!ssasDimension.Hierarchies.Contains(outerHierarchy.ID))
                    {
                        ssasHierarchy = ssasDimension.Hierarchies.Add(outerHierarchy.Name, outerHierarchy.ID);
                        ssasHierarchy.AllMemberName = "all";
                    }
                    else
                    {
                        ssasHierarchy = ssasDimension.Hierarchies[outerHierarchy.ID];
                    }

                    if (outerHierarchy.Levels != null && outerHierarchy.Levels.Count > 0)
                    {
                        CreateLevels(ssasDimension, ssasHierarchy, dataSourceView, outerHierarchy.Levels);
                    }
                }
            }
            ssasDimension.Update();
        }