public override void Initialize(object source)
        {
            var data = source as Dictionary <string, string>;

            foreach (var item in data)
            {
                var metadata = new EntityPropertyMetadata()
                {
                    Header = item.Key
                };
                var property = new CustomEntityProperty(item.Key, data, metadata);
                this.entityProperties.Add(property);
            }
        }
Esempio n. 2
0
        public IEnumerable <EntityPropertyMetadata> Build(ApplicationEntity applicationEntity)
        {
            var result = new List <EntityPropertyMetadata>();

            foreach (var applicationEntityProperty in applicationEntity.ApplicationEntityProperties)
            {
                var applicationEntityMetadataProperty = applicationEntity.ApplicationEntityMetadata.ApplicationEntityMetadataProperty.SingleOrDefault(x => x.PropertyName == applicationEntityProperty.PropertyName);

                var entityPropertyMetadata = new EntityPropertyMetadata();
                entityPropertyMetadata.PropertyName     = applicationEntityProperty.PropertyName;
                entityPropertyMetadata.TypeName         = applicationEntityProperty.DynamicTypeName;
                entityPropertyMetadata.GetValueFunction = applicationEntityProperty.GetValueFunction;
                entityPropertyMetadata.SetValueAction   = applicationEntityProperty.SetValueAction;
                if (applicationEntityProperty.IsSimple)
                {
                    entityPropertyMetadata.ParseValue     = str => applicationEntityProperty.SimpleTypeParser.Parse(str);
                    entityPropertyMetadata.SimpleTypeEnum = applicationEntityProperty.SimpleTypeParser.SimpleTypeEnum();
                }
                //copy attributes from property
                entityPropertyMetadata.EntityPropertyAttributes.AddRange(applicationEntityProperty.Attributes);
                if (applicationEntityMetadataProperty != null)
                {
                    foreach (var attribute in applicationEntityMetadataProperty.Attributes)
                    {
                        if (entityPropertyMetadata.EntityPropertyAttributes.All(x => x.GetType() != attribute.GetType()))
                        {
                            entityPropertyMetadata.EntityPropertyAttributes.Add(attribute);
                        }
                    }
                }

                entityPropertyMetadata.IsSimple        = applicationEntityProperty.IsSimple;
                entityPropertyMetadata.IsCollection    = applicationEntityProperty.IsDynamicCollection;
                entityPropertyMetadata.IsComplexEntity = applicationEntityProperty.IsComplexEntity;
                entityPropertyMetadata.IsNullableType  = applicationEntityProperty.IsNullable;
                result.Add(entityPropertyMetadata);
            }
            return(result);
        }
 public CustomEntityProperty(string propertyName, Dictionary <string, string> item, EntityPropertyMetadata metadata)
 {
     this.PropertyName = propertyName;
     this.PropertyType = typeof(string);
     this.Metadata     = metadata;
     this.dataItem     = item;
     this.IsReadOnly   = false;
 }
Esempio n. 4
0
 public CustomEntityProperty(string propertyName, Dictionary <string, string> item, EntityPropertyMetadata metadata)
 {
     this.metadata     = metadata;
     this.propertyName = propertyName;
     this.dataItem     = item;
 }
Esempio n. 5
0
        private void Load()
        {
            IClassMetadata classMetadata = m_sessionFactory.GetClassMetadata(m_persistentClass);

            if (classMetadata == null)
            {
                return;
            }

            Configuration conf            = NHibernateHelper.GetSessionFactoryManager().GetConfigurationBySessionFactory(m_sessionFactory);
            var           persistentClass = conf.GetClassMapping(m_persistentClass);

            m_idProperty   = persistentClass.GetProperty(classMetadata.IdentifierPropertyName);
            this.TableName = persistentClass.Table.Name;

            for (int i = 0; i < classMetadata.PropertyNames.Length; ++i)
            {
                string s = classMetadata.PropertyNames[i];
                NHibernate.Mapping.Property property = persistentClass.GetProperty(s);
                try
                {
                    var it = property.ColumnIterator.GetEnumerator();
                    it.MoveNext();
                    if (it.Current != null && it.Current is NHibernate.Mapping.Column)
                    {
                        int  length      = ((NHibernate.Mapping.Column)it.Current).Length;
                        bool nullability = classMetadata.PropertyNullability[i];
                        m_properties[s] = new EntityPropertyMetadata {
                            Name = s, Length = length, NotNull = !nullability
                        };
                    }
                }
                catch (System.InvalidOperationException)
                {
                }
            }

            //if (Attribute.IsDefined(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute)))
            //{
            //    Attribute[] attrs = Attribute.GetCustomAttributes(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute));
            //    if (attrs.Length > 0)
            //    {
            //        ClassAttribute attr = attrs[0] as ClassAttribute;
            //        m_tableName = attr.Table;
            //    }
            //}

            //m_propertyAttributes.Clear();
            //PropertyInfo[] pInfos = m_persistentClass.GetProperties();
            //foreach (PropertyInfo pInfo in pInfos)
            //{
            //    if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute));
            //        foreach(var i in attrs)
            //        {
            //            PropertyAttribute attr = i as PropertyAttribute;
            //            m_propertyAttributes.Add(attr.Name == null ? pInfo.Name : attr.Name, attr);
            //        }
            //    }
            //    else if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute));
            //        if (attrs.Length > 0)
            //        {
            //            m_idAttribute = attrs[0] as IdAttribute;
            //        }
            //    }
            //}
        }
        private void Load()
        {
            IClassMetadata classMetadata = m_sessionFactory.GetClassMetadata(m_persistentClass);
            if (classMetadata == null)
                return;

            Configuration conf = NHibernateHelper.GetSessionFactoryManager().GetConfigurationBySessionFactory(m_sessionFactory);
            var persistentClass = conf.GetClassMapping(m_persistentClass);

            m_idProperty = persistentClass.GetProperty(classMetadata.IdentifierPropertyName);
            this.TableName = persistentClass.Table.Name;

            for (int i = 0; i < classMetadata.PropertyNames.Length; ++i)
            {
                string s = classMetadata.PropertyNames[i];
                NHibernate.Mapping.Property property = persistentClass.GetProperty(s);
                try
                {
                    var it = property.ColumnIterator.GetEnumerator();
                    it.MoveNext();
                    if (it.Current != null && it.Current is NHibernate.Mapping.Column)
                    {
                        int length = ((NHibernate.Mapping.Column)it.Current).Length;
                        bool nullability = classMetadata.PropertyNullability[i];
                        m_properties[s] = new EntityPropertyMetadata { Name = s, Length = length, NotNull = !nullability };
                    }
                }
                catch (System.InvalidOperationException)
                {
                }
            }

            //if (Attribute.IsDefined(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute)))
            //{
            //    Attribute[] attrs = Attribute.GetCustomAttributes(m_persistentClass, typeof(NHibernate.Mapping.Attributes.ClassAttribute));
            //    if (attrs.Length > 0)
            //    {
            //        ClassAttribute attr = attrs[0] as ClassAttribute;
            //        m_tableName = attr.Table;
            //    }
            //}

            //m_propertyAttributes.Clear();
            //PropertyInfo[] pInfos = m_persistentClass.GetProperties();
            //foreach (PropertyInfo pInfo in pInfos)
            //{
            //    if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.PropertyAttribute));
            //        foreach(var i in attrs)
            //        {
            //            PropertyAttribute attr = i as PropertyAttribute;
            //            m_propertyAttributes.Add(attr.Name == null ? pInfo.Name : attr.Name, attr);
            //        }
            //    }
            //    else if (Attribute.IsDefined(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute)))
            //    {
            //        Attribute[] attrs = Attribute.GetCustomAttributes(pInfo, typeof(NHibernate.Mapping.Attributes.IdAttribute));
            //        if (attrs.Length > 0)
            //        {
            //            m_idAttribute = attrs[0] as IdAttribute;
            //        }
            //    }
            //}
        }