public TypePropertyAssociationMetadata(AssociationAttribute associationAttr) { Name = associationAttr.Name; IsForeignKey = associationAttr.IsForeignKey; OtherKeyMembers = associationAttr.OtherKeyMembers; ThisKeyMembers = associationAttr.ThisKeyMembers; }
public TypePropertyAssociationMetadata(AssociationAttribute associationAttr) { Name = associationAttr.Name; IsForeignKey = associationAttr.IsForeignKey; _otherKeyMembers = associationAttr.OtherKeyMembers.ToList <string>(); _thisKeyMembers = associationAttr.ThisKeyMembers.ToList <string>(); }
public AssociationMetadata(PropertyDescriptor pd) { this.PropertyDescriptor = pd; AttributeCollection propertyAttributes = pd.ExplicitAttributes(); this.AssociationAttribute = (AssociationAttribute)propertyAttributes[typeof(AssociationAttribute)]; this.IsExternal = propertyAttributes[typeof(ExternalReferenceAttribute)] != null; this.IsCollection = EntityGenerator.IsCollectionType(pd.PropertyType); if (!this.IsCollection) { this.PropTypeName = CodeGenUtilities.GetTypeName(pd.PropertyType); this.AssociationTypeName = @"OpenRiaServices.DomainServices.Client.EntityRef<" + this.PropTypeName + ">"; this.Attributes = propertyAttributes.Cast <Attribute>().Where(a => a.GetType() != typeof(DataMemberAttribute)); } else { this.PropTypeName = CodeGenUtilities.GetTypeName(TypeUtility.GetElementType(pd.PropertyType)); this.AssociationTypeName = "OpenRiaServices.DomainServices.Client.EntityCollection<" + this.PropTypeName + ">"; List <Attribute> attributeList = propertyAttributes.Cast <Attribute>().ToList(); ReadOnlyAttribute readOnlyAttr = propertyAttributes.OfType <ReadOnlyAttribute>().SingleOrDefault(); if (readOnlyAttr != null && !propertyAttributes.OfType <EditableAttribute>().Any()) { attributeList.Add(new EditableAttribute(!readOnlyAttr.IsReadOnly)); } this.Attributes = attributeList.Where(a => a.GetType() != typeof(DataMemberAttribute)); } this.PropertyName = CodeGenUtilities.GetSafeName(pd.Name); this.FieldName = CodeGenUtilities.MakeCompliantFieldName(this.PropertyName); }
public static void Constructor(string name, string thisKey, string otherKey, string[] thisKeyMembers, string[] otherKeyMembers) { var attribute = new AssociationAttribute(name, thisKey, otherKey); Assert.Equal(name, attribute.Name); Assert.Equal(thisKey, attribute.ThisKey); Assert.Equal(otherKey, attribute.OtherKey); if (thisKey == null) { Assert.Throws <NullReferenceException>(() => attribute.ThisKeyMembers); } else { Assert.Equal(thisKeyMembers, attribute.ThisKeyMembers); } if (otherKey == null) { Assert.Throws <NullReferenceException>(() => attribute.OtherKeyMembers); } else { Assert.Equal(otherKeyMembers, attribute.OtherKeyMembers); } }
private Type GetTypeToCreateOn(XPMemberInfo memberInfo, AssociationAttribute associationAttribute) { return !memberInfo.MemberType.IsGenericType ? (string.IsNullOrEmpty(associationAttribute.ElementTypeName) ? memberInfo.MemberType : Type.GetType(associationAttribute.ElementTypeName)) : memberInfo.MemberType.GetGenericArguments()[0]; }
public IList <MemberInfo> GetEntityRefAssociations(Type type) { // BUG: This is ignoring External Mappings from XmlMappingSource. // TODO: Should be cached in a static thread safe cache. List <MemberInfo> associations = new List <MemberInfo>(); foreach (var p in type.GetProperties()) { AssociationAttribute associationAttribute = p.GetCustomAttributes(typeof(AssociationAttribute), true).FirstOrDefault() as AssociationAttribute; if (associationAttribute != null) { FieldInfo field = type.GetField(associationAttribute.Storage, BindingFlags.NonPublic | BindingFlags.Instance); if (field != null && field.FieldType.IsGenericType && #if MONO_STRICT field.FieldType.GetGenericTypeDefinition() == typeof(System.Data.Linq.EntityRef <>) #else field.FieldType.GetGenericTypeDefinition() == typeof(DbLinq.Data.Linq.EntityRef <>) #endif ) { associations.Add(p); } } } return(associations); }
private XPCustomMemberInfo CreateMemberInfo(ITypesInfo typesInfo, IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute) { var typeToCreateOn = getTypeToCreateOn(memberInfo, associationAttribute); if (typeToCreateOn == null) throw new NotImplementedException(); XPCustomMemberInfo xpCustomMemberInfo; if (!(memberInfo.IsList) || (memberInfo.IsList && providedAssociationAttribute.RelationType == RelationType.ManyToMany)) { xpCustomMemberInfo = typesInfo.CreateCollection( typeToCreateOn, memberInfo.Owner.Type, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name + "s", false); } else { xpCustomMemberInfo = typesInfo.CreateMember( typeToCreateOn, memberInfo.Owner.Type, associationAttribute.Name, XpandModuleBase.Dictiorary, providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name, false); } if (!string.IsNullOrEmpty(providedAssociationAttribute.AssociationName) && memberInfo.FindAttribute<AssociationAttribute>() == null) memberInfo.AddAttribute(new AssociationAttribute(providedAssociationAttribute.AssociationName)); typesInfo.RefreshInfo(typeToCreateOn); return xpCustomMemberInfo; }
private void LoadRelatedPostProcess <T>( IEnumerable <T> sourceEntities, LoadRelatedOptions options, LoadRelatedPreProcessInfo preProcessInfo) { JToken[] rows = ClientAdaper.GetDocuments(preProcessInfo.EntityIdsToLoad); EntitiesProcessResult processResult = Process(rows, new OdmViewProcessingOptions()); Dictionary <string, EntitiesProcessResult> viewsSelectResult = SelectToManyFromViews(preProcessInfo); foreach (T sourceEntity in sourceEntities) { string entityId = GetEntityInstanceId(sourceEntity); JToken document = DocumentManager.DocInfo(entityId).Document; // ToOne foreach (PropertyInfo toOneProp in options.ToOne) { string relatedEntityId = GetRelatedToOneEntityId(document, toOneProp); object relatedToOneEntity = processResult.GetEntity(relatedEntityId); // This line was comment out because it is possible to get null related entity // when the property is optional. This check needs to be done only for required properties. //if (relatedToOneEntity == null) throw new Exception("Fail to find ToOne related entity for property " + toOneProp); toOneProp.SetValue(sourceEntity, relatedToOneEntity); } // ToOne already loaded foreach (PropertyInfo toOneProp in options.ToOneExist) { string relatedEntityId = GetRelatedToOneEntityId(document, toOneProp); object relatedToOneEntity = identityMap.GetEntityById(relatedEntityId); if (relatedToOneEntity == null) { throw new Exception("Fail to find ToOneExist related entity for property " + toOneProp); } toOneProp.SetValue(sourceEntity, relatedToOneEntity); } // ToMany Direct foreach (PropertyInfo toManyDirectProp in options.ToManyDirect) { string[] relatedEntitiesIds = GetRelatedToManyEntitiesIds(document, toManyDirectProp); if (relatedEntitiesIds != null) { serializer.SetDirectAssoicationCollectionProperty(sourceEntity, toManyDirectProp, relatedEntitiesIds); } } // ToMany Inverse foreach (LoadRelatedWithViewInfo toManyViewInfo in options.ToManyView) { EntitiesProcessResult viewProcessResult = viewsSelectResult[toManyViewInfo.ViewName]; string[] relatedEntitiesIds = viewProcessResult.GetRelatedEntitiesIds(entityId); AssociationAttribute associationAttr = AssociationAttribute.GetSingle(toManyViewInfo.PropertyInfo); serializer.SetInverseAssociationCollectionInternal( sourceEntity, toManyViewInfo.PropertyInfo, associationAttr, relatedEntitiesIds); } } }
static XpandCustomMemberInfo CreateMemberInfo(IModelMemberEx modelMemberEx, XPClassInfo xpClassInfo) { var calculatedMember = modelMemberEx as IModelMemberCalculated; if (calculatedMember != null) { return(xpClassInfo.CreateCalculabeMember(calculatedMember.Name, calculatedMember.Type, calculatedMember.AliasExpression)); } var modelMemberOrphanedColection = modelMemberEx as IModelMemberOrphanedColection; if (modelMemberOrphanedColection != null) { return(xpClassInfo.CreateCollection(modelMemberOrphanedColection.Name, modelMemberOrphanedColection.CollectionType.TypeInfo.Type, modelMemberOrphanedColection.Criteria)); } var modelMemberOneToManyCollection = modelMemberEx as IModelMemberOneToManyCollection; if (modelMemberOneToManyCollection != null) { var elementType = modelMemberOneToManyCollection.CollectionType.TypeInfo.Type; var associationAttribute = new AssociationAttribute(modelMemberOneToManyCollection.AssociationName, elementType); var xpandCollectionMemberInfo = xpClassInfo.CreateCollection(modelMemberOneToManyCollection.Name, elementType, null, associationAttribute); modelMemberOneToManyCollection.AssociatedMember.ModelClass.TypeInfo.FindMember(modelMemberOneToManyCollection.AssociatedMember.Name).AddAttribute(associationAttribute); return(xpandCollectionMemberInfo); } var modelMemberModelMember = modelMemberEx as IModelMemberModelMember; if (modelMemberModelMember != null) { var memberInfo = ModelMemberModelMemberDomainLogic.Get_MemberInfo(modelMemberModelMember); return((XpandCustomMemberInfo)xpClassInfo.FindMember(memberInfo.Name)); } return(xpClassInfo.CreateCustomMember(modelMemberEx.Name, modelMemberEx.Type, modelMemberEx is IModelMemberNonPersistent)); }
private void ResetAttribute() { string name = _name; if (name == null) { string type1 = typeof(TEntity).Name; string type2 = typeof(TMember).Name; if (isForeignKey) { name = type2 + "_" + type1; } else { name = type1 + "_" + type2; } } List <Attribute> memberMetaData = metadata.GetMemberMetadata(member); if (attribute != null) { memberMetaData.Remove(attribute); } attribute = new AssociationAttribute(name, MakeKey(fromKeys), MakeKey(toKeys)) { IsForeignKey = isForeignKey }; metadata.AddMetadata(member, attribute); }
private static IList <Tuple <PropertyInfo, DbEntity> > GetAllNeighbors(DbEntity entity, List <DbEntity> neighbors, AddNeighborDelegate deleg) { Type type = entity.GetType(); var propertyInfos = new List <Tuple <PropertyInfo, DbEntity> >(); // for all neighbors, check if they have a nullable reference to the current entity foreach (DbEntity neighbor in neighbors) { Type neighborType = neighbor.GetType(); foreach (var PropertyInfp in neighborType .GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(i => i.CanWrite && i.PropertyType == type)) { PropertyInfo pointerToEntity = neighborType.GetProperty(PropertyInfp.Name + "Id"); if (pointerToEntity == null) { AssociationAttribute associationAttribute = (AssociationAttribute)Attribute.GetCustomAttribute(PropertyInfp, typeof(AssociationAttribute)); if (associationAttribute != null) { pointerToEntity = neighborType.GetProperty(associationAttribute.OtherKey); } } if (pointerToEntity != null) { deleg(entity, neighbor, PropertyInfp, pointerToEntity, propertyInfos); } } } return(propertyInfos); }
public AssociationList( object owner, string[] keys, CouchDBContextImpl context, AssociationAttribute associationAttr) : base(owner, context, associationAttr) { this.keys = keys; }
private static void FillUpStorageInfoDictionary(Type type, Dictionary <string, string> mapping, Dictionary <string, SQLStorageItem> storage) { Dictionary <string, MemberInfo> _mmbrs = type.GetDictionaryOfMembers(); foreach (MemberInfo _ax in from _pidx in _mmbrs where _pidx.Value.MemberType == MemberTypes.Property select _pidx.Value) { if (mapping.ContainsKey(_ax.Name) && String.IsNullOrEmpty(mapping[_ax.Name])) { continue; } foreach (Attribute _cax in _ax.GetCustomAttributes(false)) { AssociationAttribute _ass = _cax as AssociationAttribute; if (_ass != null) { continue; } SQLStorageItem _newStorageItem = new SQLStorageItem(_ax.Name, _ax as PropertyInfo); string key = _ax.Name; if (mapping.ContainsKey(key)) { key = mapping[key]; } storage.Add(key, _newStorageItem); if (type.BaseType != typeof(Object)) { FillUpStorageInfoDictionary(type.BaseType, mapping, storage); } } } }
private static void AddOrUpdateAttribute( [NotNull] AttributedAssociation attributedAssociation, [NotNull] IField field, int fieldIndex) { Assert.ArgumentNotNull(field, nameof(field)); const bool includeDeleted = true; AssociationAttribute attribute = attributedAssociation.GetAttribute(field.Name, includeDeleted); if (attribute == null) { _msg.InfoFormat("Adding attribute {0}", field.Name); attribute = attributedAssociation.AddAttribute(field.Name, (FieldType)field.Type); } else { // attribute already registered if (attribute.Deleted) { _msg.WarnFormat( "Attribute {0} was registered as deleted, but exists now. " + "Resurrecting it...", attribute.Name); attribute.RegisterExisting(); } attribute.FieldType = (FieldType)field.Type; } // configure the attribute attribute.SortOrder = fieldIndex; }
public AssociationSet( object owner, string[] keys, CouchDBContextImpl context, AssociationAttribute associationAttr) : base(owner, context, associationAttr) { this.keys = new HashSet <string>(keys); }
public AssociationCollection( object owner, CouchDBContextImpl context, AssociationAttribute associationAttr) { this.owner = owner; this.context = context; this.associationAttr = associationAttr; }
public static int GetFieldIndex([NotNull] ITable table, [NotNull] AssociationAttribute associationAttribute, [CanBeNull] IFieldIndexCache fieldIndexCache = null) { return (fieldIndexCache?.GetFieldIndex(table, associationAttribute.Name, null) ?? GetFieldIndex(table, associationAttribute.Name, null)); }
private Type GetTypeToCreateOn(XPMemberInfo memberInfo, AssociationAttribute associationAttribute) { return(!memberInfo.MemberType.IsGenericType ? (string.IsNullOrEmpty(associationAttribute.ElementTypeName) ? memberInfo.MemberType : Type.GetType(associationAttribute.ElementTypeName)) : memberInfo.MemberType.GetGenericArguments()[0]); }
private void ProcessOnTargetRemove(FieldDef fieldDef, AssociationAttribute attribute) { if (attribute.onTargetRemove == null) { return; } fieldDef.OnTargetRemove = attribute.OnTargetRemove; }
AssociationAttribute GetAssociationAttribute(IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute) { var associationAttribute = memberInfo.FindAttribute<AssociationAttribute>(); if (associationAttribute == null && !string.IsNullOrEmpty(providedAssociationAttribute.AssociationName)) associationAttribute = new AssociationAttribute(providedAssociationAttribute.AssociationName); else if (associationAttribute == null) throw new NullReferenceException(memberInfo + " has no association attribute"); return associationAttribute; }
private void CalculateWrappedFields() { foreach (PropertyInfo field in ClassToWrap.GetProperties()) { // wrap all member PropertyWrapper wrapper = WrappingHandler.CreateFieldWrapper(this, field); WrappedFields.Put(field.Name, wrapper); // wrap persistent member if ((ClassToWrap.GetCustomAttribute <PersistentAttribute>() != null || field.HasCustomAttribute <PersistentAttribute>() || field.HasCustomAttribute <AssociationAttribute>()) && !field.HasCustomAttribute <NonPersistentAttribute>() && !wrapper.IsList) { WrappedPersistentFields.Put(field.Name, wrapper); // wrap reference member if (typeof(PersistentObject).IsAssignableFrom(field.PropertyType)) { // add to all wrappedRelations WrappedRelations.Put(field.Name, wrapper); AssociationAttribute associationAttribute = field.GetCustomAttribute <AssociationAttribute>(); // add also to anonymous or identified relations if (associationAttribute == null) { WrappedAnonymousRelations.Put(field.Name, wrapper); } else { WrappedIdentifiedAssociations.Put(associationAttribute.Name, wrapper); } } else { // wrap value Member WrappedValueMember.Put(field.Name, wrapper); } } else // wrap non persistent member { NonPersistentFields.Put(field.Name, wrapper); if (wrapper.IsList) { AssociationAttribute associationAttribute = field.GetCustomAttribute <AssociationAttribute>(); if (associationAttribute != null) { WrappedRelations.Put(field.Name, wrapper); WrappedIdentifiedAssociations.Put(associationAttribute.Name, wrapper); } } } } }
public void AddAttachMethod(Type linkTableType, AssociationAttribute assocAttrThisEnd, AssociationAttribute assocAttrOtherEnd, PropertyDescriptor prop1, PropertyDescriptor prop2) { var linkTableFullTypeName = linkTableType.FullName; var navProp1TypeFullName = prop1.PropertyType.FullName; var navProp2TypeName = prop2.PropertyType.Name; var navProp2TypeFullName = prop2.PropertyType.FullName; var navProp1NameLower = ToLowerInitial(prop1.Name); var navProp2NameLower = ToLowerInitial(prop2.Name); var thisKeyMembers = assocAttrThisEnd.ThisKeyMembers.ToList(); var otherKeyMembers = assocAttrThisEnd.OtherKeyMembers.ToList(); WriteLine(@"#region Lines added by m2m4ria code generator"); WriteLine(@"/// <summary>"); WriteLine( @"/// This method attaches {0} and {1} to the current link table entity, in such a way", navProp1TypeFullName, navProp2TypeFullName); WriteLine(@"/// that both navigation properties are set before an INotifyCollectionChanged event is fired."); WriteLine(@"/// </summary>"); WriteLine(@"/// <param name=""r""/>"); WriteLine(@"/// <param name=""{0}""/>", navProp1NameLower); WriteLine(@"/// <param name=""{0}""/>", navProp2NameLower); WriteLine( @"[System.ObsoleteAttribute(""This property is only intended for use by the M2M4Ria solution."")]"); WriteLine( @"public static void Attach{0}To{1}({2} r, {3} {4}, {5} {6})", navProp2TypeName, assocAttrOtherEnd.Name, linkTableFullTypeName, navProp1TypeFullName, navProp1NameLower, navProp2TypeFullName, navProp2NameLower); WriteLine(@"{"); WriteLine(@" var dummy = r.{0}; // this is to instantiate the EntityRef<{0}>", prop2.Name); WriteLine(@" r._{0}.Entity = {0};", navProp2NameLower); for (var i = 0; i < thisKeyMembers.Count(); i++) { var thisKeyLower = ToLowerInitial(thisKeyMembers[i]); WriteLine(@" r._{0} = {1}.{2};", thisKeyLower, navProp2NameLower, otherKeyMembers[i]); } WriteLine(@" r.{0} = {1};", prop1.Name, navProp1NameLower); WriteLine(@" r._{0}.Entity = null;", navProp2NameLower); for (var i = 0; i < thisKeyMembers.Count(); i++) { var thisKeyLower = ToLowerInitial(thisKeyMembers[i]); var keyType = linkTableType.GetProperty(thisKeyMembers[i]).PropertyType; WriteLine(@" r._{0} = default({1});", thisKeyLower, keyType.FullName); } WriteLine(@" r.{0} = {1};", prop2.Name, navProp2NameLower); WriteLine(@"}"); WriteLine(@"#endregion"); }
private static string AttributeNameNullCheck(AssociationAttribute attribute) { if (attribute == null) { return(null); } else { return(attribute.Name); } }
public override void CustomizeTypesInfo(ITypesInfo typesInfo) { base.CustomizeTypesInfo(typesInfo); foreach (var memberInfo in GetDecoratedMembers(typesInfo)) { var providedAssociationAttribute = (ProvidedAssociationAttribute)memberInfo.FindAttributeInfo(typeof(ProvidedAssociationAttribute)); AssociationAttribute associationAttribute = GetAssociationAttribute(memberInfo, providedAssociationAttribute); XPCustomMemberInfo customMemberInfo = CreateMemberInfo(typesInfo, memberInfo, providedAssociationAttribute, associationAttribute); AddExtraAttributes(memberInfo, providedAssociationAttribute, customMemberInfo); } }
private static void CreateCollectionMemberInfo(IModelMemberOneToManyCollection collection, XPClassInfo info) { var associationAttribute = new AssociationAttribute(collection.AssociationName, collection.CollectionType.TypeInfo.Type); info.CreateCollection(collection.Name, collection.CollectionType.TypeInfo.Type, null, associationAttribute); var associatedClassInfo = info.Dictionary.GetClassInfo(collection.AssociatedMember.ModelClass.TypeInfo.Type); var associatedMemberInfo = associatedClassInfo.FindMember(collection.AssociatedMember.Name); associatedMemberInfo.AddAttribute(associationAttribute); ((BaseInfo)collection.ModelClass.TypeInfo).Store.RefreshInfo(collection.AssociatedMember.ModelClass.TypeInfo); }
public static void IsForeignKey_GetSet_ReturnsExpected() { var attribute = new AssociationAttribute("Name", "ThisKey", "OtherKey"); Assert.False(attribute.IsForeignKey); attribute.IsForeignKey = true; Assert.True(attribute.IsForeignKey); attribute.IsForeignKey = false; Assert.False(attribute.IsForeignKey); }
protected override void VisitEntityCollection(IEntityCollection entityCollection, MetaMember member) { // look for any invalid updates made to composed children if (entityCollection.HasValues && member.IsComposition) { AssociationAttribute assoc = member.AssociationAttribute; foreach (Entity childEntity in entityCollection.Entities) { CheckInvalidChildUpdates(childEntity, assoc); } } }
public void IsForeignKey_GetSet_ReturnsExpected() { var attribute = new AssociationAttribute("Name", "ThisKey", "OtherKey"); Assert.False(attribute.IsForeignKey); attribute.IsForeignKey = true; Assert.True(attribute.IsForeignKey); attribute.IsForeignKey = false; Assert.False(attribute.IsForeignKey); }
public void Process(FieldDef fieldDef, AssociationAttribute attribute) { if (fieldDef.IsPrimitive || fieldDef.IsStructure) { throw new DomainBuilderException( string.Format(Strings.ExAssociationAttributeCanNotBeAppliedToXField, fieldDef.Name)); } ProcessPairTo(fieldDef, attribute); ProcessOnOwnerRemove(fieldDef, attribute); ProcessOnTargetRemove(fieldDef, attribute); }
protected override void VisitEntityCollection(IEntityCollection entityCollection, PropertyInfo propertyInfo) { // look for any invalid updates made to composed children if (propertyInfo.GetCustomAttributes(typeof(CompositionAttribute), false).Length == 1 && entityCollection.HasValues) { AssociationAttribute assoc = (AssociationAttribute)propertyInfo.GetCustomAttributes(typeof(AssociationAttribute), false).SingleOrDefault(); foreach (Entity childEntity in entityCollection.Entities) { CheckInvalidChildUpdates(childEntity, assoc); } } }
internal void SetInverseAssociationCollectionInternal( object proxy, PropertyInfo prop, AssociationAttribute associationAttr, string[] inverseKeys) { Type elementType = prop.PropertyType.GenericTypeArguments[0]; Type associateCollectionClosedType = CreateAssociateCollectionType(prop.PropertyType, elementType); object associateCollection = Activator.CreateInstance( associateCollectionClosedType, proxy, inverseKeys, context, associationAttr); prop.SetValue(proxy, associateCollection); }
private static string GetLinkTableOtherNavigationPropertyName( AssociationAttribute association, Type linkTableType) { var properties = from p in TypeDescriptor.GetProperties(linkTableType).OfType <PropertyDescriptor>() let x = p.Attributes[typeof(AssociationAttribute)] as AssociationAttribute where x != null where x.Name != association.Name select p; return(properties.Single().Name); }
private void addAttributes(IMemberInfo memberInfo, AssociationAttribute associationAttribute, ProvidedAssociationAttribute providedAssociationAttribute, XPCustomMemberInfo customMemberInfo) { customMemberInfo.AddAttribute(getAssociationAttribute(customMemberInfo.IsCollection, memberInfo.Owner.Type,associationAttribute.Name)); if (providedAssociationAttribute.AttributesFactoryProperty != null){ var property = memberInfo.Owner.Type.GetProperty(providedAssociationAttribute.AttributesFactoryProperty, BindingFlags.Static|BindingFlags.Public); if (property== null) throw new NullReferenceException(string.Format("Static propeprty {0} not found at {1}", providedAssociationAttribute.GetPropertyInfo(x=>x.AttributesFactoryProperty).Name, memberInfo.Owner.Type.FullName)); var values = (IEnumerable<Attribute>) property.GetValue(null, null); foreach (Attribute attribute in values){ customMemberInfo.AddAttribute(attribute); } } }
/// <summary> /// Verify that the specified entity does not have any modified FK members for the /// specified composition. /// </summary> /// <param name="entity">The child entity to check.</param> /// <param name="compositionAttribute">The composition attribute.</param> private static void CheckInvalidChildUpdates(Entity entity, AssociationAttribute compositionAttribute) { if (compositionAttribute == null) { return; } if (entity.EntityState == EntityState.Modified && entity.ModifiedProperties.Select(p => p.Name).Intersect(compositionAttribute.OtherKeyMembers).Any()) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.Entity_CantReparentComposedChild, entity)); } }
AssociationAttribute GetAssociationAttribute(XPMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute) { var associationAttribute = memberInfo.FindAttributeInfo(typeof(AssociationAttribute)) as AssociationAttribute; if (associationAttribute == null && !string.IsNullOrEmpty(providedAssociationAttribute.AssociationName)) { associationAttribute = new AssociationAttribute(providedAssociationAttribute.AssociationName); } else if (associationAttribute == null) { throw new NullReferenceException(memberInfo + " has no association attribute"); } return(associationAttribute); }
private XPCustomMemberInfo GetCustomMemberInfo(IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute) { XPCustomMemberInfo customMemberInfo; var typeToCreateOn = getTypeToCreateOn(memberInfo,associationAttribute); if (typeToCreateOn== null) throw new NotImplementedException(); var propertyName = providedAssociationAttribute.ProvidedPropertyName??typeToCreateOn.Name+"s"; if (memberInfo.IsAssociation || (memberInfo.IsList&&providedAssociationAttribute.RelationType==RelationType.ManyToMany)){ customMemberInfo = XafTypesInfo.Instance.CreateCollection(typeToCreateOn, memberInfo.Owner.Type, propertyName,XafTypesInfo.XpoTypeInfoSource.XPDictionary); } else customMemberInfo = XafTypesInfo.Instance.CreateMember(typeToCreateOn, memberInfo.Owner.Type, propertyName, XafTypesInfo.XpoTypeInfoSource.XPDictionary); return customMemberInfo; }
public static void Constructor(string name, string thisKey, string otherKey, string[] thisKeyMembers, string[] otherKeyMembers) { var attribute = new AssociationAttribute(name, thisKey, otherKey); Assert.Equal(name, attribute.Name); Assert.Equal(thisKey, attribute.ThisKey); Assert.Equal(otherKey, attribute.OtherKey); if (thisKey == null) { Assert.Throws<NullReferenceException>(() => attribute.ThisKeyMembers); } else { Assert.Equal(thisKeyMembers, attribute.ThisKeyMembers); } if (otherKey == null) { Assert.Throws<NullReferenceException>(() => attribute.OtherKeyMembers); } else { Assert.Equal(otherKeyMembers, attribute.OtherKeyMembers); } }
/// <summary> /// finds the <see cref="AssociationAttribute.ElementTypeName"/> of XpCollections that are marked with an <see cref="AssociationAttribute"/> given the child GridLevelNode of the focused view /// </summary> /// <returns>returns the <see cref="AssociationAttribute.Name"/></returns> public static Type FindTypeOfCollection(AssociationAttribute associationAttribute) { Assembly assembly = Assembly.Load(associationAttribute.AssemblyName); return assembly.GetType(associationAttribute.ElementTypeName, true); }
static XpandCustomMemberInfo CreateMemberInfo(IModelMemberEx modelMemberEx, XPClassInfo xpClassInfo) { var calculatedMember = modelMemberEx as IModelMemberCalculated; if (calculatedMember != null) return xpClassInfo.CreateCalculabeMember(calculatedMember.Name, calculatedMember.Type, calculatedMember.AliasExpression); var modelMemberOrphanedColection = modelMemberEx as IModelMemberOrphanedColection; if (modelMemberOrphanedColection != null) { return xpClassInfo.CreateCollection(modelMemberOrphanedColection.Name, modelMemberOrphanedColection.CollectionType.TypeInfo.Type, modelMemberOrphanedColection.Criteria); } var modelMemberOneToManyCollection = modelMemberEx as IModelMemberOneToManyCollection; if (modelMemberOneToManyCollection!=null) { var elementType = modelMemberOneToManyCollection.CollectionType.TypeInfo.Type; var associationAttribute = new AssociationAttribute(modelMemberOneToManyCollection.AssociationName, elementType); var xpandCollectionMemberInfo = xpClassInfo.CreateCollection(modelMemberOneToManyCollection.Name, elementType, null, associationAttribute); modelMemberOneToManyCollection.AssociatedMember.ModelClass.TypeInfo.FindMember(modelMemberOneToManyCollection.AssociatedMember.Name).AddAttribute(associationAttribute); return xpandCollectionMemberInfo; } return xpClassInfo.CreateCustomMember(modelMemberEx.Name, modelMemberEx.Type, modelMemberEx is IModelMemberNonPersistent); }
private Type getTypeToCreateOn(IMemberInfo memberInfo, AssociationAttribute associationAttribute) { if (!memberInfo.MemberType.IsGenericType) return string.IsNullOrEmpty(associationAttribute.ElementTypeName) ? memberInfo.MemberType : Type.GetType(associationAttribute.ElementTypeName); return memberInfo.MemberType.GetGenericArguments()[0]; }
// private bool constrainMustBeChecked(ConditionalConstrainAttribute attribute, XPMemberInfo xpMemberInfo) // { // if (attribute.FactoryType != null) // { // #region check for property // PropertyInfo property = // attribute.FactoryType.GetProperty(attribute.MethodName, BindingFlags.Static | BindingFlags.Public); // if (property != null) // { // object actualValue = property.GetValue(null, null); // // var list = new ArrayList(); // if (attribute.Value is Array) // list = new ArrayList((ICollection) attribute.Value); // else // list.Add(attribute.Value); // return list.Contains(actualValue); // } // #endregion // Attribute info = null; // if (xpMemberInfo.HasAttribute(typeof (NotNullAbleValueAttribute))) // info = xpMemberInfo.GetAttributeInfo(attribute.GetType()); // return // dataErrorInfoProvider.GetConditionalConstrainAttributeErrors(xpMemberInfo, true, new object[] {info}); // } // return !(attribute.Guid != null && excludedConstrains.Contains(attribute.Guid)); // } private void setAssociationErrors(XPMemberInfo xpMemberInfo, AssociationAttribute associationAttribute) { var dbObject = (DBObject) xpMemberInfo.GetValue(this); if (dbObject != null) dbObject[GetAssociatedCollection(associationAttribute.Name, dbObject)] = Error; }
private void setIsChangedForParentAssociation(XPMemberInfo xpMemberInfo, AssociationAttribute associationAttribute) { object value = xpMemberInfo.GetValue(this); if (value != null) ((DBObject) value).IsChanged = true; #region // foreach (XPMemberInfo xpMemberInfo in ClassInfo.PersistentProperties) // { // if ((xpMemberInfo.HasAttribute(typeof (AssociationAttribute)))) // { // AssociationAttribute associationAttribute = (AssociationAttribute) xpMemberInfo.GetAttributeInfo(typeof (AssociationAttribute)); // object[] attributes = xpMemberInfo.MemberType.GetProperty( // getAssociatedCollection(associationAttribute.Name, xpMemberInfo.ReferenceType)).GetCustomAttributes(typeof (AggregatedAttribute), false); // if (attributes.Length > 0) // { // object value = xpMemberInfo.GetValue(this); // if (value != null) // ((DBObject) value).IsChanged = true; // } // } // } #endregion }