コード例 #1
0
 public HasManyMappingException(string message, HasManyModel model)
     : base(message)
 {
     Model      = model;
     ParentType = model.ContainingTypeModel.Type;
     Property   = model.Property;
 }
コード例 #2
0
        public override void VisitHasMany(HasManyModel model)
        {
            Type   childType = model.Property.PropertyType.GetGenericArguments( ).SingleOrDefault( );
            string tableName = model.ContainingTypeModel.ActiveRecordAtt.Table;

            if (childType == null)
            {
                throw new HasManyMappingException("Property must have only one generic argument", model);
            }

            AptifyEntityMetadata parentEntity =
                this.entities.FirstOrDefault(e => e.Tables.Any(t => t.Name == tableName));
            AptifyEntityMetadata childEntity = this.mappings.GetTableMetadata(childType).Entity;

            // Can't map the table yet
            if (childEntity == null)
            {
                return;
            }

            if (childEntity.Parent == parentEntity)
            {
                parentEntity.AddChild(childEntity, model.Property.Name);
            }

            base.VisitHasMany(model);
        }
コード例 #3
0
ファイル: FormHelper.cs プロジェクト: qinfengzhu/StudyCastle
 public bool CanHandle(HasManyModel model)
 {
     if (!model.HasManyAtt.Inverse)
     {
         return(CheckModelAndKeyAreAccessible(model.HasManyAtt.MapType));
     }
     return(false);
 }
コード例 #4
0
        public String CreateControl(ActiveRecordModel model, String prefix,
                                    HasManyModel hasManyModel, object instance)
        {
            stringBuilder.Length = 0;

            var prop = hasManyModel.Property;

            prefix += "." + prop.Name;

            var otherModel = ActiveRecordModel.GetModel(hasManyModel.HasManyAtt.MapType);

            var keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            var source = CommonOperationUtils.FindAll(otherModel.Type);

            stringBuilder.Append(prop.Name + ":  ");
            stringBuilder.Append("<br/>\r\n");

            IDictionary attrs = new HybridDictionary(true);

            attrs["value"] = keyModel.Property.Name;

            var list = CreateCheckboxList(prefix, source, attrs);

            foreach (var item in list)
            {
                stringBuilder.Append(list.Item());

                stringBuilder.Append(item.ToString());

                stringBuilder.Append("<br/>\r\n");
            }

            return(stringBuilder.ToString());
        }
コード例 #5
0
ファイル: FormHelper.cs プロジェクト: qinfengzhu/StudyCastle
        public String CreateControl(ActiveRecordModel model, HasManyModel hasManyModel, object instance)
        {
            stringBuilder.Length = 0;

            PropertyInfo prop = hasManyModel.Property;

            ActiveRecordModel otherModel = ActiveRecordModel.GetModel(hasManyModel.HasManyAtt.MapType);

            PrimaryKeyModel keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            object container = InitializeRelationPropertyIfNull(instance, prop);

            object value = null;

            if (container != null)
            {
                value = CreateArrayFromExistingIds(keyModel, container as ICollection);
            }

            object[] items = CommonOperationUtils.FindAll(otherModel.Type, hasManyModel.HasManyAtt.Where);

            String propName = String.Format("{0}.{1}", prop.Name, keyModel.Property.Name);

            stringBuilder.Append(LabelFor(propName, prop.Name + ": &nbsp;"));
            stringBuilder.Append("<br/>");
            stringBuilder.Append(Select(propName, new DictHelper().CreateDict("size=6", "multiple")));
            stringBuilder.Append(CreateOptionsFromArray(items, null, keyModel.Property.Name, value));
            stringBuilder.Append(EndSelect());

            return(stringBuilder.ToString());
        }
コード例 #6
0
 public HasManyMappingException(HasManyModel model)
     : this("Could not map HasMany property", model)
 {
 }