コード例 #1
0
        private EntityColumnInfo[] InflectColumns(Type entityType, FluentEntityTableInfo fluentEti, string tableName)
        {
            var props   = entityType.GetProperties();
            var lstRetn = new List <EntityColumnInfo>(props.Length);

            foreach (var prop in props)
            {
                var fluentEci = fluentEti?.Columns?.FirstOrDefault(p => p.Property.Name == prop.Name);
                if (fluentEci?.IsIgnore == true)
                {
                    continue;
                }

                var colName         = !string.IsNullOrEmpty(fluentEci?.ColumnName) ? fluentEci.ColumnName : prop.Name;
                var isPrimaryKey    = false;
                var isAutoIncrement = false;
                if (fluentEci?.IsPrimaryKey.HasValue ?? false)
                {
                    isPrimaryKey = fluentEci.IsPrimaryKey.Value;
                }
                else if (IsPrimaryKeyName(tableName, colName))
                {
                    isPrimaryKey = true;
                }

                if (fluentEci?.IsAutoIncrement.HasValue ?? false)
                {
                    isAutoIncrement = fluentEci.IsAutoIncrement.Value;
                }
                else
                {
                    var t = prop.PropertyType;
                    if (t.GetTypeInfo().IsGenericType&& t.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        t = t.GetGenericArguments()[0];
                    }

                    if (isPrimaryKey && IsPrimaryKeyName(tableName, colName) &&
                        (t == typeof(long) || t == typeof(ulong) ||
                         t == typeof(int) || t == typeof(uint) ||
                         t == typeof(short) || t == typeof(ushort)))
                    {
                        isAutoIncrement = true;
                    }
                }

                lstRetn.Add(new EntityColumnInfo
                {
                    IsPrimaryKey    = isPrimaryKey,
                    IsAutoIncrement = isAutoIncrement,
                    ColumnName      = colName,
                    Property        = prop
                });
            }

            return(lstRetn.ToArray());
        }
コード例 #2
0
 private string InflectTableName(Type entityType, FluentEntityTableInfo fluentEti)
 {
     return(!string.IsNullOrEmpty(fluentEti?.TableName) ? fluentEti.TableName : entityType.Name);
 }