示例#1
0
        private void InitialMembers(List <MemberBase> members, List <MetadataBase> intialize, bool isInherit)
        {
            foreach (var member in members.Where(a => a.MemberType == EMemberType.Primary))
            {
                var item1 = new PropertyPrimaryData(member, this, isInherit);
                if (PrimaryPropertys.ContainsKey(member.Name))
                {
                    throw new Exception($"实体[{ProjectItem.Title}]中已存在成员[{member.Name}]。");
                }
                PrimaryPropertys.Add(member.Name, item1);
                intialize.Add(item1);
            }
            var prefix = Definition.Configure?.FastPrefixStr;

            foreach (var member in members.Where(a => a.MemberType == EMemberType.Column))
            {
                var item2 = new PropertyColumnData(member, this, isInherit);
                if (ColumnPropertys.ContainsKey(member.Name))
                {
                    throw new Exception($"实体[{ProjectItem.Title}]中已存在成员[{member.Name}]。");
                }
                ColumnPropertys.Add(member.Name, item2);
                if (Definition.CubeType == Model.Definitions.Entities.EEntityCubeType.Fact)
                {
                    if (!string.IsNullOrEmpty(prefix))
                    {
                        var col  = (ColumnMember)member;
                        var name = string.IsNullOrEmpty(col.ColumnName) ? member.Name : col.ColumnName;
                        item2.Column(prefix + name, DataColumnIndex++);
                    }
                }
                intialize.Add(item2);
            }
            if (this.Definition.CubeType == Model.Definitions.Entities.EEntityCubeType.None)
            {
                foreach (var member in members.Where(a => a.MemberType == EMemberType.Navigation))
                {
                    if (NavigationPropertys.ContainsKey(member.Name))
                    {
                        throw new Exception($"实体[{ProjectItem.Title}]中已存在成员[{member.Name}]。");
                    }

                    try
                    {
                        var item3 = new PropertyNavigationData(member, this, isInherit);
                        NavigationPropertys.Add(member.Name, item3);
                        intialize.Add(item3);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"实体[{ProjectItem.Title}]中成员[{member.Name}]存在问题!");
                    }
                }
            }
            else if (Definition.CubeType == Model.Definitions.Entities.EEntityCubeType.Fact)
            {
                foreach (var member in members.OfType <NavigationMember>())
                {
                    if (member.Cardinality == EMappingCardinality.Many && member.ToCardinality != EMappingCardinality.Many)
                    {
                        var toitem        = Project.Entitys[member.ToEntityId];
                        var toentity      = Project.Entitys[member.ToEntityId].Definition;
                        var primary       = toentity.Members.OfType <PrimaryMember>().Single();
                        var foreignMember = new ColumnMember()
                        {
                            Content    = primary.Content,
                            Name       = member.Name + primary.Name,
                            Title      = member.Title + "外键",
                            IsRequired = member.ToCardinality == EMappingCardinality.One
                        };
                        var foreigncolumn = new PropertyColumnData(foreignMember, this, false);
                        foreigncolumn.Write("AgileDesign.SsasEntityFrameworkProvider.Attributes.DimensionPropertyAttribute"
                                            , "\"" + toitem.ClassName + "s\"");
                        this.ColumnPropertys.Add(foreigncolumn.Name, foreigncolumn);
                        this.DimEntityPropertys.Add(foreignMember.Name, foreigncolumn);
                        intialize.Add(foreigncolumn);
                    }
                }
                foreach (var member in members.OfType <DimensionMember>())
                {
                    if (!Project.Entitys.ContainsKey(member.DimensionEntityId))
                    {
                        throw new Exception($"实体[{ProjectItem.Title}]中维度成员[{member.Title}]所关联的实体[{member.DimensionEntityId}]不存在。");
                    }
                    var dimmember = new PropertyDimMemberData(member, this, false);
                    this.DimMemberPropertys.Add(dimmember.Name, dimmember);
                    intialize.Add(dimmember);
                }
            }
            foreach (var member in members.Where(a => a.MemberType == EMemberType.Calculate))
            {
                var item4 = new PropertyCalculateData(member, this, isInherit);
                CalculatePropertys.Add(member.Name, item4);
                intialize.Add(item4);
            }
            foreach (var member in members.Where(a => a.MemberType == EMemberType.Common))
            {
                var item5 = new PropertyCommonData(member, this, isInherit);
                CommonPropertys.Add(member.Name, item5);
                intialize.Add(item5);
            }
        }
示例#2
0
            public RelationDataItem(PropertyNavigationData navi)
            {
                FromEntity   = navi.Entity;
                FromNavigate = navi;
                ToEntity     = navi.ToEntity;
                ToNavigate   = navi.ToNavigation;

                var member = navi.Member;

                if (ToNavigate != null && ToNavigate.Member.IsMain)
                {
                    member = ToNavigate.Member;
                }
                CascadeOnDelete = member.CascadeOnDelete;

                AllowCascadeOnDelete = !(member.Cardinality == EMappingCardinality.Many && member.ToCardinality == EMappingCardinality.Many);
                if (member.Cardinality == EMappingCardinality.Many && member.ToCardinality != EMappingCardinality.Many)
                {
                    AllownForeignKey = true;
                }
                if (member.Cardinality != EMappingCardinality.Many && member.ToCardinality == EMappingCardinality.Many)
                {
                    AllownForeignKey = true;
                }

                if (AllownForeignKey)
                {
                    //目前只支持单个外键
                    var foreignkey    = member.ForeignKeyName;
                    var targetEntity  = navi.Member.Cardinality == EMappingCardinality.Many ? navi.Entity : navi.ToEntity;
                    var primaryEntity = navi.Member.Cardinality == EMappingCardinality.Many ? navi.ToEntity : navi.Entity;
                    PropertyColumnData  foreigncolumn  = null;
                    PropertyPrimaryData foreigncolumn2 = null;
                    if (string.IsNullOrEmpty(foreignkey) ||
                        !(targetEntity.ColumnPropertys.TryGetValue(foreignkey, out foreigncolumn) ||
                          targetEntity.PrimaryPropertys.TryGetValue(foreignkey, out foreigncolumn2)))
                    {
                        var    primaryColumn = primaryEntity.PrimaryPropertys.Values.First();
                        string foreignName   = GenerateForeignName(targetEntity, primaryEntity.ClassName + primaryColumn.Name);

                        var content = primaryColumn.Member.Content;
                        content = (DataTypeBase)content.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(content, new object[] { });

                        bool isrequired = true;
                        if (navi.Member.Cardinality != EMappingCardinality.Many)
                        {
                            isrequired = navi.Member.Cardinality == EMappingCardinality.One;
                        }
                        else if (navi.Member.ToCardinality != EMappingCardinality.Many)
                        {
                            isrequired = navi.Member.ToCardinality == EMappingCardinality.One;
                        }

                        ColumnMember foreignMember = new ColumnMember()
                        {
                            Content    = content,
                            Name       = foreignName,
                            Title      = navi.Member.Title + "外键",
                            IsRequired = isrequired
                        };
                        foreigncolumn = new PropertyColumnData(foreignMember, targetEntity, navi.IsInherit);
                        foreigncolumn.Initialize(navi.Project);
                        targetEntity.ColumnPropertys.Add(foreignMember.Name, foreigncolumn);
                    }
                    if (foreigncolumn != null)
                    {
                        foreigncolumn.Index(false);
                        ForeignKeyName = foreigncolumn.Name;
                    }
                    else if (foreigncolumn2 != null)
                    {
                        ForeignKeyName = foreigncolumn2.Name;
                    }
                }
            }