Esempio n. 1
0
        internal void AutoMapColumns <T>(params Expression <Func <T, object> >[] ignorePropertyExpressions)
        {
            //此代码只能被执行一次
            if (this._autoMappedAlreadyCalled)
            {
                throw new DBClientException("AutoMap cannot be called more than once.");
            }
            this._autoMappedAlreadyCalled = true;

            var properties          = ReflectionHelper.GetProperties(_data.Item.GetType());
            var ignorePropertyNames = new HashSet <string>();

            //添加要过滤的名单
            if (ignorePropertyExpressions != null && ignorePropertyExpressions.Length > 0)
            {
                foreach (var ignorePropertyExpression in ignorePropertyExpressions)
                {
                    var ignorePropertyName = new PropertyExpressionParser <T>(_data.Item, ignorePropertyExpression).Name;
                    ignorePropertyNames.Add(ignorePropertyName);
                }
            }
            //添加字段
            foreach (var property in properties)
            {
                if (!ignorePropertyNames.Contains(property.Key))//如果此字段不存在
                {
                    if (ReflectionHelper.IsBasicClrType(property.Value.PropertyType))
                    {
                        this.Column(property.Key, ReflectionHelper.GetPropertyValue(_data.Item, property.Value), DbType.Object, property.Value.PropertyType);
                    }
                }
            }
        }
Esempio n. 2
0
        internal void Where <T>(Expression <Func <T, object> > expression, DbType parameterType, int size)
        {
            var parser = new PropertyExpressionParser <T>(this._data.Item, expression);

            this.Where(parser.Name, parser.Value, parameterType, size);
        }