Example #1
0
 /// <summary>
 /// 获取Grid项的逗号
 /// </summary>
 /// <param name="property">属性</param>
 public string GetGridComma(Property property)
 {
     return(GetGridProperties().Last() == property ? "" : ",");
 }
Example #2
0
 /// <summary>
 /// 是否最后一个属性
 /// </summary>
 public bool IsLast(Property property, bool isExcludeVersion = true)
 {
     return(GetProperties(isExcludeVersion).Last() == property);
 }
Example #3
0
 /// <summary>
 /// 获取逗号
 /// </summary>
 /// <param name="property">属性</param>
 /// <param name="isExcludeVersion">是否排除版本号</param>
 public string GetComma(Property property, bool isExcludeVersion = true)
 {
     return(IsLast(property, isExcludeVersion) ? "" : ",");
 }
Example #4
0
        private void CreateProperties(Entity entity, TableSchema tableSchema)
        {
            foreach (ColumnSchema columnSchema in tableSchema.Columns)
            {
                // skip unsupported type
                if (columnSchema.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase) ||
                    columnSchema.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase))
                {
                    Debug.WriteLine(string.Format("Skipping column '{0}' because it has an unsupported db type '{1}'.",
                                                  columnSchema.Name, columnSchema.NativeType));
                    continue;
                }

                Property property = entity.Properties.ByColumn(columnSchema.Name);

                if (property == null)
                {
                    property = new Property {
                        ColumnName = columnSchema.Name
                    };
                    entity.Properties.Add(property);
                }

                string propertyName = ToPropertyName(entity.ClassName, columnSchema.Name);
                propertyName = _namer.UniqueName(entity.ClassName, propertyName);

                property.PropertyName = propertyName;
                property.Description  = columnSchema.Description;
                property.DataType     = columnSchema.DataType;
                property.SystemType   = columnSchema.SystemType;
                property.NativeType   = columnSchema.NativeType;

                property.IsPrimaryKey = columnSchema.IsPrimaryKeyMember;
                property.IsForeignKey = columnSchema.IsForeignKeyMember;
                property.IsNullable   = columnSchema.AllowDBNull;

                property.IsIdentity      = IsIdentity(columnSchema);
                property.IsRowVersion    = IsRowVersion(columnSchema);
                property.IsAutoGenerated = IsDbGenerated(columnSchema);

                if (columnSchema.IsUnique)
                {
                    property.IsUnique = columnSchema.IsUnique;
                }

                if (property.SystemType == typeof(string) ||
                    property.SystemType == typeof(byte[]))
                {
                    property.MaxLength = columnSchema.Size;
                }

                if (property.SystemType == typeof(float) ||
                    property.SystemType == typeof(double) ||
                    property.SystemType == typeof(decimal))
                {
                    property.Precision = columnSchema.Precision;
                    property.Scale     = columnSchema.Scale;
                }

                property.IsProcessed = true;
            }

            entity.Properties.IsProcessed = true;
        }