Пример #1
0
        /// <summary>
        /// 添加成员
        /// </summary>
        /// <param name="member"></param>
        /// <param name="byImport">是否导入的成员,是则不再生成标识</param>
        internal void AddMember(EntityMemberModel member, bool byImport = false)
        {
            CheckDesignMode();
            CheckOwner(member.Owner);

            if (!byImport)
            {
                //TODO:通过设计时上下文获取ApplicationModel是否导入,从而确认当前Layer
                var layer = ModelLayer.DEV;
                var seq   = layer == ModelLayer.DEV ? ++_devMemberIdSeq : ++_usrMemberIdSeq;
                if (seq >= MaxMemberId)
                {
                    throw new Exception("MemberId out of range");
                }

                ushort memberId = (ushort)(seq << IdUtil.MEMBERID_SEQ_OFFSET | (ushort)layer << IdUtil.MEMBERID_LAYER_OFFSET);
                member.InitMemberId(memberId);
            }
            Members.Add(member);

            if (!member.AllowNull) //注意仅none nullable
            {
                ChangeSchemaVersion();
            }
            OnPropertyChanged();
        }
Пример #2
0
        /// <summary>
        /// Only used for StoreInitiator
        /// </summary>
        internal void AddSysMember(EntityMemberModel member, ushort id)
        {
            CheckDesignMode();
            CheckOwner(member.Owner);

            member.InitMemberId(id); //注意:传入id已处理Layer标记位
            Members.Add(member);
        }
Пример #3
0
 internal virtual void UpdateFrom(EntityMemberModel from)
 {
     if (Name != from.Name)
     {
         Name = from.Name;
         //TODO:如果字典表重构,从字典表中移除旧名称,添加新名称 Owner.RenameMember()
     }
     AllowNull = from.AllowNull;
     Comment   = from.Comment;
 }
Пример #4
0
        /// <summary>
        /// 重命名成员
        /// </summary>
        internal void RenameMember(string oldName, string newName)
        {
            CheckDesignMode();
            if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName))
            {
                throw new ArgumentNullException();
            }
            if (oldName == newName)
            {
                Log.Warn("Rename: name is same");
                return;
            }

            EntityMemberModel m = GetMember(oldName);

            m.RenameTo(newName);
            //TODO: 如果改为字典表以下需要重新加入
            //Members.Remove(oldName);
            //Members.Add(newName, m);
        }
Пример #5
0
        /// <summary>
        /// 根据成员名称删除成员,如果是EntityRef成员同时删除相关隐藏成员
        /// </summary>
        internal void RemoveMember(string memberName)
        {
            CheckDesignMode();
            EntityMemberModel m = GetMember(memberName, true);

            //如果实体模型是新建的或成员是新建的直接移除
            if (PersistentState == Data.PersistentState.Detached ||
                m.PersistentState == Data.PersistentState.Detached)
            {
                if (m is EntityRefModel refModel)
                {
                    foreach (var fk in refModel.FKMemberIds)
                    {
                        Members.Remove(GetMember(fk, true));
                    }
                    if (refModel.IsAggregationRef)
                    {
                        Members.Remove(GetMember(refModel.TypeMemberId, true));
                    }
                }
                Members.Remove(m);
                return;
            }

            //标为删除状态
            m.MarkDeleted();
            if (m is EntityRefModel refModel2)
            {
                foreach (var fk in refModel2.FKMemberIds)
                {
                    GetMember(fk, true).MarkDeleted();
                }
                if (refModel2.IsAggregationRef)
                {
                    GetMember(refModel2.TypeMemberId, true).MarkDeleted();
                }
            }

            ChangeSchemaVersion();
            OnPropertyChanged();
        }