Пример #1
0
        public static void Fill(this DbDataReader sdr, ValueSet ds)
        {
            ValueTable valueTable = ds.Tables.Add();

            for (int i = 0; i < sdr.FieldCount; i++)
            {
                valueTable.Columns.Add(sdr.GetName(i), sdr.GetFieldType(i), sdr.GetDataTypeName(i));
            }
            while (sdr.Read())
            {
                ValueRow item = valueTable.NewRow();
                for (int j = 0; j < sdr.FieldCount; j++)
                {
                    item.ItemArray[j] = sdr[j];
                }
                valueTable.Rows.Add(item);
            }
            if (sdr.NextResult())
            {
                sdr.Fill(ds);
            }
        }
Пример #2
0
 public static T ToVo <T>(this ValueRow dr, T vo, bool useAlias = false)
     where T : ValueObject
 {
     return(ValueRowExtension._ToVo <T>(dr, vo, useAlias));
 }
Пример #3
0
        internal static T _ToVo <T>(ValueRow dr, T vo, bool useAlias)
            where T : ValueObject
        {
            Type reflectedType;
            Type type = typeof(T);

            if (dr == null)
            {
                if (vo != null)
                {
                    return(vo);
                }
                return(default(T));
            }
            if (vo == null)
            {
                vo = Activator.CreateInstance <T>();
            }
            BaseEntity baseEntity = (object)vo as BaseEntity;

            if (baseEntity != null)
            {
                baseEntity.SetValueRow(dr);
            }
            else
            {
            }
            ValueTable table = dr.Table;

            foreach (ValueColumn column in dr.Table.Columns)
            {
                string       columnName   = column.ColumnName;
                PropertyInfo propertyInfo = null;
                if (table.mappingOrinal != null)
                {
                    foreach (Tuple <Type, bool> tuple in table.mappingOrinal)
                    {
                        Type item1 = tuple.Item1;
                        ((tuple.Item2 ? ValueObject.DataMappingAlias[item1] : ValueObject.DataMapping[item1])).TryGetValue(columnName, out propertyInfo);
                        if (propertyInfo == null)
                        {
                            continue;
                        }
                        goto Label0;
                    }
                }
                else
                {
                    ((useAlias ? ValueObject.DataMappingAlias[type] : ValueObject.DataMapping[type])).TryGetValue(columnName, out propertyInfo);
                }
Label0:
                Type type1 = typeof(T);
                if (propertyInfo != null)
                {
                    reflectedType = propertyInfo.ReflectedType;
                }
                else
                {
                    reflectedType = null;
                }
                if (type1 != reflectedType)
                {
                    continue;
                }
                object item = dr[column.ColumnOrdinal.Value];
                vo.Invoke(item, propertyInfo);
            }
            return(vo);
        }
Пример #4
0
        public string BuildEntity(string tablename)
        {
            MapperProvider defaultProvider = MapperProvider.DefaultProvider;
            string         str             = string.Concat("SELECT * FROM ", tablename);
            ValueSet       valueSet        = defaultProvider.QueryForValueSet(str, null, CommandType.Text);
            StringBuilder  stringBuilder   = new StringBuilder();

            stringBuilder.AppendLine("using Test.Core;");
            stringBuilder.AppendLine("using System;");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine(string.Concat("namespace ", this._namespace));
            stringBuilder.AppendLine("{");
            str = string.Concat("select object_id from sys.all_objects where type_desc='USER_TABLE' and name='", tablename, "'");
            string        str1 = defaultProvider.QueryForScalar(str, null, CommandType.Text).ToString();
            List <string> strs = new List <string>();

            str = string.Concat("select * from sys.columns where object_id='", str1, "'");
            ValueTable item = defaultProvider.QueryForValueSet(str, null, CommandType.Text).Tables[0];

            str = string.Concat("select * from sys.index_columns where object_id='", str1, "'");
            ValueTable    valueTable = defaultProvider.QueryForValueSet(str, null, CommandType.Text).Tables[0];
            List <string> strs1      = new List <string>();

            foreach (ValueRow row in valueTable.Rows)
            {
                str = string.Concat(new object[] { "select name from sys.columns where object_id='", str1, "' AND column_id='", row["column_id"], "'" });
                string str2 = defaultProvider.QueryForScalar(str, null, CommandType.Text).ToString();
                strs1.Add(str2);
            }
            stringBuilder.AppendLine(string.Format("\tpublic class {0}Entity : BaseEntity", this.GetCName(tablename, "TB_")));
            stringBuilder.AppendLine("\t{");
            foreach (ValueColumn column in valueSet.Tables[0].Columns)
            {
                ValueRow valueRow = item.Rows.FirstOrDefault <ValueRow>((ValueRow p) => p["name"].ToString() == column.ColumnName);
                string   str3     = "string";
                string   str4     = column.DataType.ToString();
                if (str4 == "System.Int32")
                {
                    str3 = "int";
                }
                else if (str4 == "System.Int64")
                {
                    str3 = "long";
                }
                else if (str4 == "System.Double")
                {
                    str3 = "double";
                }
                else if (str4 == "System.Single")
                {
                    str3 = "float";
                }
                else if (str4 == "System.DateTime")
                {
                    str3 = "DateTime";
                }
                else
                {
                    str3 = (str4 == "System.Boolean" ? "bool" : "string");
                }
                stringBuilder.AppendFormat(string.Concat("\t\t[Column(\"", column.ColumnName, "\", "), Array.Empty <object>());
                str = string.Concat("select name from sys.types where system_type_id='", valueRow["system_type_id"], "'");
                string       name    = defaultProvider.QueryForScalar(str, null, CommandType.Text).ToString();
                MemberInfo[] members = typeof(SqlDataType).GetMembers();
                for (int i = 0; i < (int)members.Length; i++)
                {
                    MemberInfo memberInfo = members[i];
                    if (memberInfo.Name.ToLower() == name)
                    {
                        name = memberInfo.Name;
                    }
                }
                stringBuilder.AppendFormat(", SqlDataType.{0}", name);
                if ((!(bool)valueRow["is_nullable"] || column.Unique || strs1.Contains(column.ColumnName)) && strs1.Contains(column.ColumnName))
                {
                    stringBuilder.AppendFormat("SqlColumnType.PrimaryKey", Array.Empty <object>());
                }
                stringBuilder.AppendLine(")]");
                stringBuilder.AppendLine(string.Format("\t\tpublic {0} {1} {{ get; set; }}", str3, this.GetCName(column.ColumnName, "")));
                stringBuilder.AppendLine();
            }
            stringBuilder.AppendLine("\t}");
            stringBuilder.AppendLine("}");
            return(stringBuilder.ToString());
        }
Пример #5
0
 internal void SetValueRow(ValueRow data)
 {
     this.data = data;
 }