コード例 #1
0
        private PropertyInfo[] SelectProps(IEnumerable <PropertyInfo> props, Dictionary <string, object> values, CreateCommandOption option)
        {
            List <PropertyInfo> list = new List <PropertyInfo>();

            foreach (var prop in props)
            {
                if (_Tablename.Equals(prop.Name))
                {
                    continue;
                }
                var name = GetColumnName(prop);
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                if (!option.HasDesignatedProperties(prop.Name))
                {
                    var isDefaultValue = false;
                    var val            = values[prop.Name];
                    if (val == null)
                    {
                        continue;
                    }

                    switch (val.GetType().Name.ToLower())
                    {
                    case "int64":
                        isDefaultValue = Convert.ToInt64(val) == default(long);
                        break;

                    case "int32":
                        isDefaultValue = Convert.ToInt32(val) == default(int);
                        break;

                    case "int16":
                        isDefaultValue = Convert.ToInt16(val) == default(short);
                        break;

                    case "datetime":
                        isDefaultValue = Convert.ToDateTime(val) == default(DateTime);
                        break;
                    }

                    var attr = GetColumnAttribute(prop);
                    if (attr != null && attr.IsDbGenerated && isDefaultValue)
                    {
                        continue;
                    }
                }
                list.Add(prop);
            }
            return(list.ToArray());
        }
コード例 #2
0
        private string[] GetParameterColumnNamesWithoutPrimaryKey(IEnumerable <PropertyInfo> props, Dictionary <string, object> values, CreateCommandOption option)
        {
            var columns = new List <string>();

            foreach (var prop in props)
            {
                if (_Tablename.Equals(prop.Name))
                {
                    continue;
                }
                var name = GetColumnName(prop);
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }
                var attr = GetColumnAttribute(prop);
                if (attr != null && (attr.IsDbGenerated || attr.IsPrimaryKey))
                {
                    continue;
                }
                if (!option.HasDesignatedProperties(prop.Name))
                {
                    var val = values[prop.Name];
                    if (val == null)
                    {
                        continue;
                    }
                }
                if (option != null && option.WhereProperties != null && option.WhereProperties.Any() && option.WhereProperties.Contains(prop.Name))
                {
                    continue;
                }

                columns.Add(name);
            }
            return(columns.ToArray());
        }