コード例 #1
0
        public static string GetTableName(this ICURDProperties updateProperties, string tableIndex = null, int id = 0)
        {
            var tableAttribute = updateProperties.GetCustomerAttributes <MatchedTableAttribute>().FirstOrDefault(w => w.ID == id);
            var tableName      = tableAttribute?.Name;

            if (string.IsNullOrEmpty(tableName))
            {
                tableName = updateProperties.GetType().Name;
            }
            //tableName = tableName.Trim();//Support Use Sencond Type TableIndex For Table FullName
            var    ITableSharding  = updateProperties as ITableSharding;
            string tableNameFormat = string.Empty;

            if (ITableSharding != null)
            {
                tableNameFormat = string.Format(tableName, ITableSharding.__TableIndex__);
                if (tableIndex == null)
                {
                    return(tableNameFormat);
                }
            }
            if (tableName.StartsWith("{") && tableName.EndsWith("}"))
            {
                tableName = AppSetting.GetConfig(tableName.TrimStart('{').TrimEnd('}'));
            }
            if (tableName.Contains("{") && tableName.Contains("}"))
            {
                tableNameFormat = string.Format(tableName, tableIndex);
                return(tableNameFormat);
            }
            return(tableName);
        }
コード例 #2
0
ファイル: WhereExtend.cs プロジェクト: HiriswHe/FourBeauties
        public static List <string> GetMatchedKeyNameAndValues(this ICURDProperties updateProperties, int id = 0)
        {
            List <string> result = new List <string>();

            if (updateProperties == null)
            {
                return(result);
            }
            var properties = updateProperties.GetType().GetProperties();

            result.Add(" Where 1=0 ");
            if (properties != null)
            {
                foreach (var property in properties)
                {
                    if (property.IgnoreProperty(updateProperties, id))
                    {
                        continue;
                    }
                    var matchedKeyAttribute = property.GetCustomAttributes(typeof(MatchedKeysAttribute), true).Select(w => w as MatchedKeysAttribute).FirstOrDefault(w => w.ID == id);
                    if (matchedKeyAttribute != null)
                    {
                        var key = property.Name;
                        result.Add(string.Format("and {0}=@{0}", key));
                    }
                    var matchedColumnAttribute = property.GetCustomAttributes(typeof(MatchedColumnAttribute), true).Select(w => w as MatchedColumnAttribute).FirstOrDefault(w => w.ID == id);
                    if (matchedColumnAttribute != null)
                    {
                        var columnName = matchedColumnAttribute.AliasName;
                        if (string.IsNullOrEmpty(columnName))
                        {
                            columnName = property.Name;
                        }
                        var contactNotation = matchedColumnAttribute.ContactNotation;
                        var columnValue     = "@" + property.Name;
                        var filterRelation  = matchedColumnAttribute.FilterRelation;
                        if (string.Compare(contactNotation, "like", true) == 0 && property.PropertyType == typeof(string))
                        {
                            property.SetValue(updateProperties, "%" + property.GetValue(updateProperties, null) + "%");
                        }
                        result.Add(string.Format(" {0} {1} {2} {3} ", filterRelation, columnName, contactNotation, columnValue));
                    }
                }
            }
            if (result.Count > 1 && !string.IsNullOrEmpty(result[1]))
            {
                result[1] = result[1].Replace("And", "Or ( ");
                result[result.Count - 1] += " ) ";
            }
            return(result);
        }
コード例 #3
0
ファイル: WhereExtend.cs プロジェクト: HiriswHe/FourBeauties
        public static List <string> GetInMatchedKeyNameAndValues(this ICURDProperties updateProperties, int id = 0, bool ignoreMatched = false, params List <object>[] listsIn)
        {
            List <string> result = new List <string>();

            if (updateProperties == null)
            {
                return(result);
            }
            var properties = updateProperties.GetType().GetProperties();

            result.Add(" Where 1=0 ");
            bool hasMatchedColumn = false;
            int  i = 0;

            if (properties != null)
            {
                foreach (var property in properties)
                {
                    if (!hasMatchedColumn && property.MatchedProperty(updateProperties, id) != null)
                    {
                        hasMatchedColumn = true;
                    }
                    if (!ignoreMatched && property.IgnoreProperty(updateProperties, id))
                    {
                        continue;
                    }
                    if (ignoreMatched && property.IgnoreMatchedProperty(updateProperties, id))
                    {
                        continue;
                    }
                    var matchedKeyAttribute = property.GetCustomAttributes(typeof(MatchedKeysAttribute), true).Select(w => w as MatchedKeysAttribute).FirstOrDefault(w => w.ID == id);
                    if (matchedKeyAttribute != null)
                    {
                        var key = property.Name;
                        result.Add(string.Format("And {0}=@{0}", key));
                    }
                    var matchedColumnAttribute = property.GetCustomAttributes(typeof(MatchedColumnAttribute), true).Select(w => w as MatchedColumnAttribute).FirstOrDefault(w => w.ID == id);
                    if (matchedColumnAttribute != null)
                    {
                        var columnName = matchedColumnAttribute.AliasName;
                        if (string.IsNullOrEmpty(columnName))
                        {
                            columnName = property.Name;
                        }
                        var contactNotation = matchedColumnAttribute.ContactNotation;
                        var columnValue     = "@" + property.Name;
                        var filterRelation  = matchedColumnAttribute.FilterRelation;
                        if (string.Compare(contactNotation, "like", true) == 0 && property.PropertyType == typeof(string))
                        {
                            property.SetValue(updateProperties, "%" + property.GetValue(updateProperties, null) + "%");
                        }
                        if (!string.IsNullOrEmpty(contactNotation) && contactNotation.ToUpper().Contains("IN") && listsIn != null && listsIn.Length > i)
                        {
                            columnValue = property.GetColumnInValue(i, listsIn);
                            result.Add(string.Format(" {0} {1} {2} {3} ", filterRelation, columnName, contactNotation, columnValue));
                            i++;
                        }
                        else
                        {
                            if (property.GetValue(updateProperties, null) == null && contactNotation == "=")
                            {
                                contactNotation = "is"; columnValue = "null";
                            }
                            result.Add(string.Format(" {0} {1} {2} {3} ", filterRelation, columnName, contactNotation, columnValue));
                        }
                    }
                }
            }
            if (result.Count == 1 && hasMatchedColumn)
            {
                return(new List <string>());
            }
            if (result.Count > 1 && !string.IsNullOrEmpty(result[1]))
            {
                result[1] = result[1].Replace("And", "Or ( ");
                result[result.Count - 1] += " ) ";
            }
            return(result);
        }