示例#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;
        }
示例#2
0
        private void CreateCube(Database database, DataSource dataSource, DataSourceView dataSourceView, CubeEntity cube)
        {
            Cube ssasCube = database.Cubes.Find(cube.ID);
            if (ssasCube != null)
                ssasCube.Drop();

            ssasCube = database.Cubes.Add(cube.Name, cube.ID);
            ssasCube.Source = new DataSourceViewBinding(dataSourceView.ID);
            ssasCube.StorageMode = StorageMode.Molap;
            ssasCube.Visible = true;
            foreach (var item in cube.Dimensions)
            {
                ssasCube.Dimensions.Add(item.ID);
            }

            var defaultGroup = ssasCube.MeasureGroups.Add("Default");
            defaultGroup.StorageMode = StorageMode.Molap;
            defaultGroup.ProcessingMode = ProcessingMode.LazyAggregations;

            foreach (var outerMeasure in cube.Measures)
            {
                var ssasMeasure = defaultGroup.Measures.Add(outerMeasure.Name, outerMeasure.ID);
                ssasMeasure.Source = this.CreateDataItem(dataSourceView, cube.TableName, outerMeasure.ColumnName);
                ssasMeasure.AggregateFunction = this.GetAggregator(outerMeasure.Aggregator);
                //measure.FormatString = format;// "000,000.##";
                //measure.Description = description;
                //measure.DisplayFolder = folderName;
                ssasMeasure.Visible = outerMeasure.Visable;
            }
            foreach (var dim in cube.Dimensions)
            {
                var cubeDim = ssasCube.Dimensions.Find(dim.ID);
                var groupDim = defaultGroup.Dimensions.Add(dim.ID);
                string levelId = "";
                for (int i = 0; i < cubeDim.Attributes.Count; i++)
                {
                    if (cubeDim.Dimension.Attributes[i].Usage == AttributeUsage.Key)
                    {
                        levelId = cubeDim.Dimension.Attributes[i].ID;
                        break;
                    }
                }
                var measureGroupAttribute = groupDim.Attributes.Add(levelId);
                measureGroupAttribute.Type = MeasureGroupAttributeType.Granularity;

                measureGroupAttribute.KeyColumns.Add(CreateDataItem(dataSourceView, cube.TableName, dim.FKColumn));

            }
            CreatePartition(defaultGroup, dataSource, cube.TableName, DateTime.Now);
            ssasCube.Update(UpdateOptions.ExpandFull);
            ssasCube.Process();
        }