Example #1
0
        private static TypeMetadata CreateTypeMetadata(PersistentClass cm, ICollection<NHibernate.Mapping.Collection> collectionMappings)
        {
            var result = new TypeMetadata { Type = cm.MappedClass };

            result.KeyProperty = AddPropertyMetadata(result, cm.IdentifierProperty);
            string classFullName = cm.MappedClass.FullName;
            foreach (var collectionMapping in collectionMappings)
            {
                if (collectionMapping.Owner == cm && collectionMapping.Role.StartsWith(classFullName))
                {
                    result.Properties.Add(new PropertyMetadata
                    {
                        Name = collectionMapping.Role.Substring(classFullName.Length + 1),
                        RelationType = collectionMapping.IsOneToMany ? RelationType.OneToMany : RelationType.ManyToMany
                    });
                }
            }
            foreach (var property in cm.PropertyIterator)
            {
                AddPropertyMetadata(result, property);
            }


            return result;
        }
Example #2
0
        private static PropertyMetadata AddPropertyMetadata(TypeMetadata typeMetadata, Property property)
        {
            PropertyMetadata propertyMetadata = new PropertyMetadata
            {
                Name = property.Name,
                RelationType = property.IsEntityRelation ? RelationType.Reference : RelationType.Value
            };

            typeMetadata.Properties.Add(propertyMetadata);
            return propertyMetadata;
        }
Example #3
0
 private static void AddProperties(TypeMetadata metadata, IEnumerable<Property> properties)
 {
     foreach (var property in properties)
     {
         if (!metadata.Properties.Any(p => p.Name == property.Name))
         {
             AddPropertyMetadata(metadata, property);
         }
     }
 }