private void WriteTreeAssociations() { var supportTree = this.EntityMeta.IsTreeEntity; if (supportTree) { foreach (var property in this.EntityMeta.EntityProperties) { if (property.ManagedProperty == Entity.TreePIdProperty) { _entityModel.associations.Add(new BelongsToAssociation { associationKey = "TreeParent", foreignKey = property.Name, model = ClientEntities.GetClientName(this.EntityMeta.EntityType), }); _entityModel.associations.Add(new HasManyAssociation { name = "TreeChildren", foreignKey = property.Name, model = ClientEntities.GetClientName(this.EntityMeta.EntityType), }); break; } } } }
private void WriteChildren() { var em = this.EntityMeta; var children = em.ChildrenProperties; for (int i = 0, c = children.Count; i < c; i++) { var child = children[i]; var listProperty = child.ManagedProperty as IListProperty; if (listProperty.HasManyType == HasManyType.Composition) { var pRefMeta = child.ChildType.FindParentReferenceProperty(); if (pRefMeta != null) { var childType = child.ChildType.EntityType; var association = new HasManyAssociation { name = child.Name, foreignKey = (pRefMeta.ManagedProperty as IRefProperty).RefIdProperty.Name, model = ClientEntities.GetClientName(childType), }; _entityModel.associations.Add(association); } } } }
private static ModuleJson ToJson(WebModuleMeta module) { var mJson = new ModuleJson { keyLabel = module.KeyLabel }; if (module.HasUI) { if (module.IsCustomUI) { mJson.url = module.Url; } else { mJson.model = ClientEntities.GetClientName(module.EntityType); mJson.clientRuntime = module.ClientRuntime; mJson.viewName = module.AggtBlocksName; } } foreach (WebModuleMeta child in module.Children) { var childJson = ToJson(child); mJson.children.Add(childJson); } return(mJson); }
private void WriteReference() { var properties = this.EntityMeta.EntityProperties; for (int i = 0, c = properties.Count; i < c; i++) { var property = properties[i]; var refProperty = property.ManagedProperty as IRefEntityProperty; if (refProperty != null) { var association = new BelongsToAssociation { associationKey = refProperty.RefEntityProperty.Name, foreignKey = refProperty.RefIdProperty.Name, model = ClientEntities.GetClientName(refProperty.RefEntityType), }; _entityModel.associations.Add(association); } } }
private static object ConvertOutputComponent(object value) { //服务的输出属性如果类型是一个实体或者实体列表,则需要进行格式转换。 if (value is IDomainComponent) { var model = (value as IDomainComponent).GetRepository().EntityType; //TODO:这里可能存在问题:当一个非默认的视图请求这个服务得到一个默认视图的实体数据时,可能会因为列不一致而出现问题。 var defaultVM = UIModel.Views.CreateBaseView(model); if (value is EntityList) { var listRes = new EntityJsonList { model = model }; EntityJsonConverter.EntityToJson(defaultVM, value as EntityList, listRes.entities); listRes.total = listRes.entities.Count; value = listRes; } else if (value is Entity) { var entityJson = new EntityJson(); EntityJsonConverter.EntityToJson(defaultVM, value as Entity, entityJson); //在纯数据的基础上添加以下两个约定的属性:标记这是一个实体以及它在客户端的类型名称。 entityJson.SetProperty(Consts.isEntityProperty, BooleanBoxes.True); entityJson.SetProperty(Consts.modelProperty, ClientEntities.GetClientName(model)); value = entityJson; } else { throw new NotSupportedException("只支持对实体、实体列表进行格式转换。"); } } return(value); }