Пример #1
0
        public IEnumerable <PropertyDescriptor> GetPrimaryKeyProperties(IBaseModel entity)
        {
            var propertySet = entity.GetProperties();

            if (propertySet == null)
            {
                yield break;
            }

            foreach (var key in propertySet.Keys)
            {
                var propertyInfo = propertySet[key] as PropertyDescriptor;
                if (propertyInfo == null)
                {
                    continue;
                }

                var propertyValue = propertyInfo.GetValue(entity);
                if (propertyValue == null)
                {
                    continue;
                }

                var dataFieldAttribute = propertyInfo.Attributes[typeof(DataFieldAttribute)] as DataFieldAttribute;
                if (!dataFieldAttribute.PrimaryKey)
                {
                    continue;
                }

                yield return(propertyInfo);
            }
        }