Exemple #1
0
        /// <summary>
        /// 仅CqlStore
        /// </summary>
        private static void ChangeClusteringColumns(EntityModel entityModel, string value)
        {
            if (entityModel.PersistentState != PersistentState.Detached)
            {
                throw new NotSupportedException("Can't change pk for none new EntityModel");
            }

            var array = JArray.Parse(value);

            if (array.Count == 0)
            {
                entityModel.CqlStoreOptions.PrimaryKey.ClusteringColumns = null;
            }
            else
            {
                var newvalue = new FieldWithOrder[array.Count];
                for (int i = 0; i < array.Count; i++)
                {
                    newvalue[i] = new FieldWithOrder()
                    {
                        MemberId    = (ushort)array[i]["MemberId"],
                        OrderByDesc = (bool)array[i]["OrderByDesc"]
                    };
                }
                entityModel.CqlStoreOptions.PrimaryKey.ClusteringColumns = newvalue;
            }
            OnCqlPKChanged(entityModel);//改变主键成员的AllowNull
        }
Exemple #2
0
        /// <summary>
        /// SysStore及SqlStore通用
        /// </summary>
        private static IndexModelBase AddIndex(EntityModel entityModel, string value)
        {
            if (entityModel.StoreOptions == null)
            {
                throw new InvalidOperationException("Can't add index for DTO");
            }

            var indexInfo = JsonConvert.DeserializeObject <IndexInfo>(value);

            //Validate
            if (string.IsNullOrEmpty(indexInfo.Name))
            {
                throw new Exception("Index has no name");
            }
            if (!CodeHelper.IsValidIdentifier(indexInfo.Name))
            {
                throw new Exception("Index name not valid");
            }
            if (indexInfo.Fields == null || indexInfo.Fields.Length == 0)
            {
                throw new Exception("Index has no fields");
            }
            if (entityModel.StoreOptions.HasIndexes &&
                entityModel.StoreOptions.Indexes.Any(t => t.Name == indexInfo.Name))
            {
                throw new Exception("Index name has existed");
            }

            var fields = new FieldWithOrder[indexInfo.Fields.Length];

            for (int i = 0; i < indexInfo.Fields.Length; i++)
            {
                fields[i] = new FieldWithOrder(indexInfo.Fields[i].MID, indexInfo.Fields[i].OrderByDesc);
            }

            //根据存储类型新建索引并添加至模型内
            if (entityModel.SysStoreOptions != null)
            {
                var newIndex = new EntityIndexModel(entityModel, indexInfo.Name, indexInfo.Unique, fields, null);
                entityModel.SysStoreOptions.AddIndex(entityModel, newIndex);
                return(newIndex);
            }
            else
            {
                var newIndex = new SqlIndexModel(entityModel, indexInfo.Name, indexInfo.Unique, fields, null);
                entityModel.SqlStoreOptions.AddIndex(entityModel, newIndex);
                return(newIndex);
            }
        }