public void HandleManyToOne(ISerializableObject handledItem, ManyToOneAttribute attr, FieldInfo field) { if (_mode == UPMODE) { field.SetValue(handledItem, null); } }
public void HandleManyToOne(ISerializableObject handledItem, ManyToOneAttribute attr, FieldInfo field) { Type type = field.FieldType; IVirtualKey vKey = AttributeWorker.GetInstance(_serializer.Target).CreateVirtualKey(_serializer, type, handledItem.GetType()); try { vKey.InitVirtualKeyByTarget(handledItem); } catch (InvalidOperationException) { field.SetValue(handledItem, null); return; } IRestriction r = Restrictions.RestrictionFactory.SqlRestriction(type, vKey.ToSqlStringBackward(_serializer.Target)); ISerializableObject tmp = _serializer.Connector.Load(type, r); field.SetValue(handledItem, tmp); }
public void HandleManyToOne(ISerializableObject handledItem, ManyToOneAttribute attr, FieldInfo field) { ISerializableObject iso = (ISerializableObject)field.GetValue(handledItem); if (iso != null) { try { SyncContainer s = _pooledObjects[AttributeWorker.RowGuid(iso)]; if (!_owner._parents.Contains(s)) { _owner._parents.Add(s); } if (!s._children.Contains(_owner)) { s._children.Add(_owner); } } catch (KeyNotFoundException) { } } }
/// <summary> Write a ManyToOne XML Element from attributes in a member. </summary> public virtual void WriteManyToOne(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ManyToOneAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "many-to-one" ); // Attribute: <name> writer.WriteAttributeString("name", attribute.Name==null ? DefaultHelper.Get_ManyToOne_Name_DefaultValue(member) : GetAttributeValue(attribute.Name, mappedClass)); // Attribute: <access> if(attribute.Access != null) writer.WriteAttributeString("access", GetAttributeValue(attribute.Access, mappedClass)); // Attribute: <class> if(attribute.Class != null) writer.WriteAttributeString("class", GetAttributeValue(attribute.Class, mappedClass)); // Attribute: <entity-name> if(attribute.EntityName != null) writer.WriteAttributeString("entity-name", GetAttributeValue(attribute.EntityName, mappedClass)); // Attribute: <column> if(attribute.Column != null) writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass)); // Attribute: <not-null> if( attribute.NotNullSpecified ) writer.WriteAttributeString("not-null", attribute.NotNull ? "true" : "false"); // Attribute: <unique> if( attribute.UniqueSpecified ) writer.WriteAttributeString("unique", attribute.Unique ? "true" : "false"); // Attribute: <unique-key> if(attribute.UniqueKey != null) writer.WriteAttributeString("unique-key", GetAttributeValue(attribute.UniqueKey, mappedClass)); // Attribute: <index> if(attribute.Index != null) writer.WriteAttributeString("index", GetAttributeValue(attribute.Index, mappedClass)); // Attribute: <cascade> if(attribute.Cascade != null) writer.WriteAttributeString("cascade", GetAttributeValue(attribute.Cascade, mappedClass)); // Attribute: <outer-join> if(attribute.OuterJoin != OuterJoinStrategy.Unspecified) writer.WriteAttributeString("outer-join", GetXmlEnumValue(typeof(OuterJoinStrategy), attribute.OuterJoin)); // Attribute: <fetch> if(attribute.Fetch != FetchMode.Unspecified) writer.WriteAttributeString("fetch", GetXmlEnumValue(typeof(FetchMode), attribute.Fetch)); // Attribute: <update> if( attribute.UpdateSpecified ) writer.WriteAttributeString("update", attribute.Update ? "true" : "false"); // Attribute: <insert> if( attribute.InsertSpecified ) writer.WriteAttributeString("insert", attribute.Insert ? "true" : "false"); // Attribute: <optimistic-lock> if( attribute.OptimisticLockSpecified ) writer.WriteAttributeString("optimistic-lock", attribute.OptimisticLock ? "true" : "false"); // Attribute: <foreign-key> if(attribute.ForeignKey != null) writer.WriteAttributeString("foreign-key", GetAttributeValue(attribute.ForeignKey, mappedClass)); // Attribute: <property-ref> if(attribute.PropertyRef != null) writer.WriteAttributeString("property-ref", GetAttributeValue(attribute.PropertyRef, mappedClass)); // Attribute: <formula> if(attribute.Formula != null) writer.WriteAttributeString("formula", GetAttributeValue(attribute.Formula, mappedClass)); // Attribute: <lazy> if(attribute.Lazy != Laziness.Unspecified) writer.WriteAttributeString("lazy", GetXmlEnumValue(typeof(Laziness), attribute.Lazy)); // Attribute: <not-found> if(attribute.NotFound != NotFoundMode.Unspecified) writer.WriteAttributeString("not-found", GetXmlEnumValue(typeof(NotFoundMode), attribute.NotFound)); // Attribute: <node> if(attribute.Node != null) writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass)); // Attribute: <embed-xml> if( attribute.EmbedXmlSpecified ) writer.WriteAttributeString("embed-xml", attribute.EmbedXml ? "true" : "false"); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the ManyToOneAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is ManyToOneAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <meta> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(MetaAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is ManyToOneAttribute ) break; // Following attributes are for this ManyToOne if( memberAttrib is MetaAttribute ) WriteMeta(writer, member, memberAttrib as MetaAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(MetaAttribute), attribute); // Element: <column> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is ManyToOneAttribute ) break; // Following attributes are for this ManyToOne if( memberAttrib is ColumnAttribute ) WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute); // Element: <formula> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(FormulaAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is ManyToOneAttribute ) break; // Following attributes are for this ManyToOne if( memberAttrib is FormulaAttribute ) WriteFormula(writer, member, memberAttrib as FormulaAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(FormulaAttribute), attribute); writer.WriteEndElement(); }
public void HandleManyToOne(ISerializableObject handledItem, ManyToOneAttribute attr, FieldInfo field) { }
/// <summary> /// Δημιουργεί ένα νέο αντικείμενο μεταδεδομένων στήλης / πεδίου οντότητας /// </summary> /// <param name="FieldInfo"></param> public ColumnMetadata(FieldInfo FieldInfo) { this.FieldInfo = FieldInfo ?? throw new ArgumentNullException(nameof(FieldInfo)); this.FieldInfo = FieldInfo; this.FieldName = FieldInfo.Name; this.FieldType = FieldInfo.FieldType; //Get Attributes ColumnAttribute column = this.FieldInfo.GetCustomAttribute <ColumnAttribute>(); CustomColumnAttribute customColumn = this.FieldInfo.GetCustomAttribute <CustomColumnAttribute>(); ManyToOneAttribute manyToOne = this.FieldInfo.GetCustomAttribute <ManyToOneAttribute>(); OneToManyAttribute oneToMany = this.FieldInfo.GetCustomAttribute <OneToManyAttribute>(); if (column == null && customColumn == null && oneToMany == null) { throw new MetadataException("This field does not contain any Column information"); } this.IsIdentifier = (this.FieldInfo.GetCustomAttribute <IdentityAttribute>() != null); if (column != null) { this.ColumnName = column.ColumnName; this.ColumnType = GetType(column.ColumnType); this.IsNullable = column.Nullable; this.IsUnique = column.Unique; } if (customColumn != null) { this.IsCustomColumn = true; //This is hardcoded since our database names the column that stores the value "CustomFieldValue" this.ColumnName = "CustomFieldValue"; this.ColumnType = GetType(customColumn.ColumnType); //Default values this.IsNullable = true; this.IsUnique = false; this.CustomFieldTable = customColumn.CustomTableName; this.CustomFieldId = customColumn.CustomFieldId; this.CustomFieldReference = customColumn.IdentifierColumn; } if (manyToOne != null) { this.IsRelationship = true; this.TargetEntity = manyToOne.TargetEntity; this.RelationshipReferenceColumn = manyToOne.IdentifierColumn; this.RelationshipType = RelationshipType.ManyToOne; } if (oneToMany != null) { this.IsRelationship = true; this.TargetEntity = oneToMany.TargetEntity; this.RelationshipReferenceColumn = oneToMany.IdentifierColumn; this.RelationshipType = RelationshipType.OneToMany; } //ADDED Row Guid this.IsRowGuid = (this.FieldInfo.GetCustomAttribute <GuidAttribute>() != null); var version = this.FieldInfo.GetCustomAttribute <VersionAttribute>(); IsVersion = (version != null); }