Esempio n. 1
0
        private List <string> _GetActualColumnNames(Type entityType, string tableName, List <string> columnList)
        {
            List <string> columnString = new List <string>();

            foreach (PropertyInfo prop in entityType.GetProperties())
            {
                KeyAttribute keyAttr = prop.GetCustomAttribute <KeyAttribute>(false);

                if (keyAttr != null)
                {
                    DbOptionAttribute dbOptionAttr = prop.GetCustomAttribute <DbOptionAttribute>(false);

                    if (dbOptionAttr == null)
                    {
                        continue;
                    }

                    if (dbOptionAttr.Option == DbGenerateOption.AutoIncrement)
                    {
                        continue;
                    }
                }

                string columnName = _entityMapper.MapColumn(prop, columnList);

                if (!string.IsNullOrEmpty(columnName))
                {
                    columnString.Add(columnName);
                }
            }

            return(columnString);
        }
Esempio n. 2
0
        private List <string> _GetEntityValues <TEntity>(IEnumerable <TEntity> param, List <string> columnString)
        {
            List <string> entityValueList = new List <string>();

            foreach (TEntity entity in param)
            {
                List <object> objectValues = new List <object>();

                PropertyInfo[] props = entity.GetType().GetProperties();

                foreach (string col in columnString)
                {
                    PropertyInfo prop = props.SingleOrDefault(p => p.Name == col);

                    if (prop == null)
                    {
                        prop = props.SingleOrDefault(p =>
                        {
                            ColumnNameAttribute collNameAttribute = p.GetCustomAttributes <ColumnNameAttribute>(false).FirstOrDefault();
                            if (collNameAttribute == null)
                            {
                                return(false);
                            }

                            return(collNameAttribute.ColumnName == col);
                        });
                    }

                    IgnoreAttribute ignoreAttr = prop.GetCustomAttributes <IgnoreAttribute>(false).FirstOrDefault();

                    if (ignoreAttr != null)
                    {
                        continue;
                    }

                    KeyAttribute keyAttr = prop.GetCustomAttribute <KeyAttribute>(false);

                    if (keyAttr != null)
                    {
                        DbOptionAttribute dbOptionAttr = prop.GetCustomAttribute <DbOptionAttribute>(false);

                        if (dbOptionAttr == null)
                        {
                            continue;
                        }

                        if (dbOptionAttr.Option == DbGenerateOption.AutoIncrement)
                        {
                            continue;
                        }
                    }

                    string value = "";

                    if (prop.GetValue(entity) is DateTime)
                    {
                        value = (Convert.ToDateTime(prop.GetValue(entity).ToString())).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        value = prop.GetValue(entity).ToString();
                    }

                    objectValues.Add(string.Format("'{0}'", MySqlHelper.EscapeString(value)));
                }

                entityValueList.Add(string.Format("({0})", string.Join(", ", objectValues)));
            }

            return(entityValueList);
        }