源代码改用vs默认格式化

This commit is contained in:
28810
2019-06-27 09:40:35 +08:00
parent 873364c7ee
commit f8c3608fda
309 changed files with 73814 additions and 67594 deletions

View File

@ -1,76 +1,83 @@
using System;
using System.Linq;
namespace FreeSql.DataAnnotations {
public class ColumnAttribute : Attribute {
namespace FreeSql.DataAnnotations
{
public class ColumnAttribute : Attribute
{
/// <summary>
/// 数据库列名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 指定数据库旧的列名修改实体属性命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库字段否则将视为【新增字段】
/// </summary>
public string OldName { get; set; }
/// <summary>
/// 数据库类型,如: varchar(255)
/// </summary>
public string DbType { get; set; }
/// <summary>
/// 数据库列名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 指定数据库旧的列名修改实体属性命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库字段否则将视为【新增字段】
/// </summary>
public string OldName { get; set; }
/// <summary>
/// 数据库类型,如: varchar(255)
/// </summary>
public string DbType { get; set; }
internal bool? _IsPrimary, _IsIdentity, _IsNullable, _IsIgnore, _IsVersion;
/// <summary>
/// 主键
/// </summary>
public bool IsPrimary { get => _IsPrimary ?? false; set => _IsPrimary = value; }
/// <summary>
/// 自增标识
/// </summary>
public bool IsIdentity { get => _IsIdentity ?? false; set => _IsIdentity = value; }
/// <summary>
/// 是否可DBNull
/// </summary>
public bool IsNullable { get => _IsNullable ?? false; set => _IsNullable = value; }
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public bool IsIgnore { get => _IsIgnore ?? false; set => _IsIgnore = value; }
/// <summary>
/// 设置行锁(乐观锁)版本号,每次更新累加版本号,若更新整个实体时会附带当前的版本号判断(修改失败时抛出异常)
/// </summary>
public bool IsVersion { get => _IsVersion ?? false; set => _IsVersion = value; }
internal bool? _IsPrimary, _IsIdentity, _IsNullable, _IsIgnore, _IsVersion;
/// <summary>
/// 主键
/// </summary>
public bool IsPrimary { get => _IsPrimary ?? false; set => _IsPrimary = value; }
/// <summary>
/// 自增标识
/// </summary>
public bool IsIdentity { get => _IsIdentity ?? false; set => _IsIdentity = value; }
/// <summary>
/// 是否可DBNull
/// </summary>
public bool IsNullable { get => _IsNullable ?? false; set => _IsNullable = value; }
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public bool IsIgnore { get => _IsIgnore ?? false; set => _IsIgnore = value; }
/// <summary>
/// 设置行锁(乐观锁)版本号,每次更新累加版本号,若更新整个实体时会附带当前的版本号判断(修改失败时抛出异常)
/// </summary>
public bool IsVersion { get => _IsVersion ?? false; set => _IsVersion = value; }
internal string[] _Uniques;
/// <summary>
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
/// </summary>
public string Unique {
get => _Uniques == null ? null : string.Join(", ", _Uniques);
set {
if (string.IsNullOrEmpty(value)) {
_Uniques = null;
return;
}
var val = value?.Trim(' ', '\t', ',');
if (string.IsNullOrEmpty(val)) {
_Uniques = null;
return;
}
var arr = val.Split(',').Select(a => a.Trim(' ', '\t').Trim()).Where(a => !string.IsNullOrEmpty(a)).ToArray();
if (arr.Any() == false) {
_Uniques = null;
return;
}
_Uniques = arr;
}
}
/// <summary>
/// 数据库默认值
/// </summary>
public object DbDefautValue { get; internal set; }
internal string[] _Uniques;
/// <summary>
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
/// </summary>
public string Unique
{
get => _Uniques == null ? null : string.Join(", ", _Uniques);
set
{
if (string.IsNullOrEmpty(value))
{
_Uniques = null;
return;
}
var val = value?.Trim(' ', '\t', ',');
if (string.IsNullOrEmpty(val))
{
_Uniques = null;
return;
}
var arr = val.Split(',').Select(a => a.Trim(' ', '\t').Trim()).Where(a => !string.IsNullOrEmpty(a)).ToArray();
if (arr.Any() == false)
{
_Uniques = null;
return;
}
_Uniques = arr;
}
}
/// <summary>
/// 数据库默认值
/// </summary>
public object DbDefautValue { get; internal set; }
/// <summary>
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
/// </summary>
public Type MapType { get; set; }
}
/// <summary>
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
/// </summary>
public Type MapType { get; set; }
}
}

View File

@ -1,87 +1,100 @@
using System;
namespace FreeSql.DataAnnotations {
public class ColumnFluent {
namespace FreeSql.DataAnnotations
{
public class ColumnFluent
{
public ColumnFluent(ColumnAttribute column) {
_column = column;
}
public ColumnFluent(ColumnAttribute column)
{
_column = column;
}
ColumnAttribute _column;
/// <summary>
/// 数据库列名
/// </summary>
public ColumnFluent Name(string value) {
_column.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的列名修改实体属性命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库字段否则将视为【新增字段】
/// </summary>
public ColumnFluent OldName(string value) {
_column.OldName = value;
return this;
}
/// <summary>
/// 数据库类型,如: varchar(255)
/// </summary>
public ColumnFluent DbType(string value) {
_column.DbType = value;
return this;
}
ColumnAttribute _column;
/// <summary>
/// 数据库列名
/// </summary>
public ColumnFluent Name(string value)
{
_column.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的列名修改实体属性命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库字段否则将视为【新增字段】
/// </summary>
public ColumnFluent OldName(string value)
{
_column.OldName = value;
return this;
}
/// <summary>
/// 数据库类型,如: varchar(255)
/// </summary>
public ColumnFluent DbType(string value)
{
_column.DbType = value;
return this;
}
/// <summary>
/// 主键
/// </summary>
public ColumnFluent IsPrimary(bool value) {
_column.IsPrimary = value;
return this;
}
/// <summary>
/// 自增标识
/// </summary>
public ColumnFluent IsIdentity(bool value) {
_column.IsIdentity = value;
return this;
}
/// <summary>
/// 是否可DBNull
/// </summary>
public ColumnFluent IsNullable(bool value) {
_column.IsNullable = value;
return this;
}
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public ColumnFluent IsIgnore(bool value) {
_column.IsIgnore = value;
return this;
}
/// <summary>
/// 乐观锁
/// </summary>
public ColumnFluent IsVersion(bool value) {
_column.IsVersion = value;
return this;
}
/// <summary>
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
/// </summary>
/// <param name="value">标识</param>
/// <returns></returns>
public ColumnFluent Unique(string value) {
_column.Unique = value;
return this;
}
/// <summary>
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public ColumnFluent MapType(Type type) {
_column.MapType = type;
return this;
}
}
/// <summary>
/// 主键
/// </summary>
public ColumnFluent IsPrimary(bool value)
{
_column.IsPrimary = value;
return this;
}
/// <summary>
/// 自增标识
/// </summary>
public ColumnFluent IsIdentity(bool value)
{
_column.IsIdentity = value;
return this;
}
/// <summary>
/// 是否可DBNull
/// </summary>
public ColumnFluent IsNullable(bool value)
{
_column.IsNullable = value;
return this;
}
/// <summary>
/// 忽略此列,不迁移、不插入
/// </summary>
public ColumnFluent IsIgnore(bool value)
{
_column.IsIgnore = value;
return this;
}
/// <summary>
/// 乐观锁
/// </summary>
public ColumnFluent IsVersion(bool value)
{
_column.IsVersion = value;
return this;
}
/// <summary>
/// 唯一键,在多个属性指定相同的标识,代表联合键;可使用逗号分割多个 UniqueKey 名。
/// </summary>
/// <param name="value">标识</param>
/// <returns></returns>
public ColumnFluent Unique(string value)
{
_column.Unique = value;
return this;
}
/// <summary>
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public ColumnFluent MapType(Type type)
{
_column.MapType = type;
return this;
}
}
}

View File

@ -1,16 +1,19 @@
using System;
using System.Linq;
namespace FreeSql.DataAnnotations {
public class NavigateAttribute : Attribute {
namespace FreeSql.DataAnnotations
{
public class NavigateAttribute : Attribute
{
/// <summary>
/// 导航属性,手工绑定
/// </summary>
public string Bind { get; set; }
/// <summary>
/// 导航属性,手工绑定
/// </summary>
public string Bind { get; set; }
public NavigateAttribute(string bind) {
this.Bind = bind;
}
}
public NavigateAttribute(string bind)
{
this.Bind = bind;
}
}
}

View File

@ -1,28 +1,30 @@
using System;
using System.Collections.Concurrent;
namespace FreeSql.DataAnnotations {
public class TableAttribute : Attribute {
namespace FreeSql.DataAnnotations
{
public class TableAttribute : Attribute
{
/// <summary>
/// 数据库表名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public string OldName { get; set; }
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public string SelectFilter { get; set; }
/// <summary>
/// 数据库表名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public string OldName { get; set; }
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public string SelectFilter { get; set; }
internal bool? _DisableSyncStructure;
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public bool DisableSyncStructure { get => _DisableSyncStructure ?? false; set => _DisableSyncStructure = value; }
internal bool? _DisableSyncStructure;
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public bool DisableSyncStructure { get => _DisableSyncStructure ?? false; set => _DisableSyncStructure = value; }
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
}
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
}
}

View File

@ -4,97 +4,112 @@ using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace FreeSql.DataAnnotations {
public class TableFluent {
namespace FreeSql.DataAnnotations
{
public class TableFluent
{
public TableFluent(Type entityType, TableAttribute table) {
_entityType = entityType;
_properties = _entityType.GetProperties().ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
_table = table;
}
public TableFluent(Type entityType, TableAttribute table)
{
_entityType = entityType;
_properties = _entityType.GetProperties().ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
_table = table;
}
Type _entityType;
Dictionary<string, PropertyInfo> _properties;
TableAttribute _table;
/// <summary>
/// 数据库表名
/// </summary>
public TableFluent Name(string value) {
_table.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public TableFluent OldName(string value) {
_table.OldName = value;
return this;
}
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public TableFluent SelectFilter(string value) {
_table.SelectFilter = value;
return this;
}
Type _entityType;
Dictionary<string, PropertyInfo> _properties;
TableAttribute _table;
/// <summary>
/// 数据库表名
/// </summary>
public TableFluent Name(string value)
{
_table.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public TableFluent OldName(string value)
{
_table.OldName = value;
return this;
}
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public TableFluent SelectFilter(string value)
{
_table.SelectFilter = value;
return this;
}
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public TableFluent DisableSyncStructure(bool value) {
_table.DisableSyncStructure = value;
return this;
}
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public TableFluent DisableSyncStructure(bool value)
{
_table.DisableSyncStructure = value;
return this;
}
public ColumnFluent Property(string proto) {
if (_properties.ContainsKey(proto) == false) throw new KeyNotFoundException($"找不到属性名 {proto}");
var col = _table._columns.GetOrAdd(proto, name => new ColumnAttribute { Name = proto });
return new ColumnFluent(col);
}
}
public ColumnFluent Property(string proto)
{
if (_properties.ContainsKey(proto) == false) throw new KeyNotFoundException($"找不到属性名 {proto}");
var col = _table._columns.GetOrAdd(proto, name => new ColumnAttribute { Name = proto });
return new ColumnFluent(col);
}
}
public class TableFluent<T> {
public class TableFluent<T>
{
public TableFluent(TableAttribute table) {
_table = table;
}
public TableFluent(TableAttribute table)
{
_table = table;
}
TableAttribute _table;
/// <summary>
/// 数据库表名
/// </summary>
public TableFluent<T> Name(string value) {
_table.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public TableFluent<T> OldName(string value) {
_table.OldName = value;
return this;
}
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public TableFluent<T> SelectFilter(string value) {
_table.SelectFilter = value;
return this;
}
TableAttribute _table;
/// <summary>
/// 数据库表名
/// </summary>
public TableFluent<T> Name(string value)
{
_table.Name = value;
return this;
}
/// <summary>
/// 指定数据库旧的表名修改实体命名时同时设置此参数为修改之前的值CodeFirst才可以正确修改数据库表否则将视为【创建新表】
/// </summary>
public TableFluent<T> OldName(string value)
{
_table.OldName = value;
return this;
}
/// <summary>
/// 查询过滤SQL实现类似 a.IsDeleted = 1 功能
/// </summary>
public TableFluent<T> SelectFilter(string value)
{
_table.SelectFilter = value;
return this;
}
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public TableFluent<T> DisableSyncStructure(bool value) {
_table.DisableSyncStructure = value;
return this;
}
/// <summary>
/// 禁用 CodeFirst 同步结构迁移
/// </summary>
public TableFluent<T> DisableSyncStructure(bool value)
{
_table.DisableSyncStructure = value;
return this;
}
public ColumnFluent Property<TProto>(Expression<Func<T, TProto>> column) {
var proto = (column.Body as MemberExpression)?.Member;
if (proto == null) throw new FormatException($"错误的表达式格式 {column}");
var col = _table._columns.GetOrAdd(proto.Name, name => new ColumnAttribute { Name = proto.Name });
return new ColumnFluent(col);
}
}
public ColumnFluent Property<TProto>(Expression<Func<T, TProto>> column)
{
var proto = (column.Body as MemberExpression)?.Member;
if (proto == null) throw new FormatException($"错误的表达式格式 {column}");
var col = _table._columns.GetOrAdd(proto.Name, name => new ColumnAttribute { Name = proto.Name });
return new ColumnFluent(col);
}
}
}