コード例 #1
0
ファイル: Map.cs プロジェクト: eicrosoft/VipSoft
 private static string GetDbString(ColumnInfo columnInfo, object v)
 {
     if (!IsNull(v))
     {
         if (columnInfo.IsNullable && IsNullValue(v)) return "NULL";
         if (columnInfo.PropertyType == typeof(string) || columnInfo.PropertyType == typeof(DateTime)) return string.Format("'{0}'", v);
         return v.ToString();
     }
     if (!columnInfo.IsNullable)
     {
         if (columnInfo.PropertyType == typeof(string)) return "''";
         return columnInfo.PropertyType == typeof(DateTime) ? string.Format("'{0}'", MinDateString) : "0";
     }
     return "NULL";
 }
コード例 #2
0
ファイル: Configuration.cs プロジェクト: eicrosoft/VipSoft
        private static ClassMetadata CreatePersistentClass(System.Type type)
        {
            ClassMetadata result = null;

            if (type != null)
            {
                result = new ClassMetadata { EntityType = type, EntityName = type.Name };

                var at = type.GetCustomAttributes(false);
                if (at.Length > 0)
                {
                    var tableAttribute = (TableAttribute)at[0];
                    result.TableName = tableAttribute.Name;
                    result.TableName = tableAttribute.Name;
                    result.AssociateTable = tableAttribute.AssociateTable;
                    result.ForeignKey = tableAttribute.ForeignKey;
                }
                var columnInfos = new List<ColumnInfo>();
                var propertyInfos = type.GetProperties();
                ColumnInfo model;
                foreach (var info in propertyInfos)
                {
                    model = new ColumnInfo { PropertyInfo = info };
                    var attributes = info.GetCustomAttributes(false);
                    foreach (var att in attributes)
                    {
                        if (att is ColumnAttribute)
                        {
                            var ptt = att as ColumnAttribute;
                            model.PropertyName = info.Name;
                            model.PropertyType = info.PropertyType.IsGenericType && info.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? info.PropertyType.GetGenericArguments()[0] : info.PropertyType;
                            if (ptt.IsPrimaryKey)
                            {
                                result.PrimaryKey = info.Name;
                                result.PKColumnName = ptt.Name;
                            }
                            model.IsIncrement = ptt.IsIncrement;
                            model.IsNullable = ptt.IsNullable;
                            model.IsUnique = ptt.IsUnique;
                            model.ParameterDirection = ptt.ParameterDirection;
                            model.SameParameters = ptt.SameParameters;
                            model.IsColumn = true;
                            model.Name = ptt.Name;
                            model.IsPrimaryKey = ptt.IsPrimaryKey;

                            model.IsInsertable = ptt.IsInsertable;

                            model.IsUpdatable = ptt.IsUnique;

                            model.ColumnDefinition = ptt.ColumnDefinition;

                            model.Table = ptt.Table;

                            model.Length = ptt.Length;

                            model.Precision = ptt.Precision;

                            model.Scale = ptt.Scale;

                        }
                        else
                        {
                            //break;
                        }
                    }
                    if (info.DeclaringType != typeof(IEntity))
                        columnInfos.Add(model);
                }
                result.ColumnInfos = columnInfos;
            }
            return result;
        }