- 增加 NavigateAttribute 特性对应的 Fluent 功能;#96

This commit is contained in:
28810
2019-09-26 11:51:50 +08:00
parent 31a42e750e
commit c747d39db8
5 changed files with 51 additions and 2 deletions

View File

@ -26,5 +26,6 @@ namespace FreeSql.DataAnnotations
public bool DisableSyncStructure { get => _DisableSyncStructure ?? false; set => _DisableSyncStructure = value; }
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
internal ConcurrentDictionary<string, NavigateAttribute> _navigates { get; } = new ConcurrentDictionary<string, NavigateAttribute>(StringComparer.CurrentCultureIgnoreCase);
}
}

View File

@ -111,5 +111,22 @@ namespace FreeSql.DataAnnotations
var col = _table._columns.GetOrAdd(proto.Name, name => new ColumnAttribute { Name = proto.Name });
return new ColumnFluent(col);
}
/// <summary>
/// 导航关系Fluent与 NavigateAttribute 对应
/// </summary>
/// <typeparam name="TProto"></typeparam>
/// <param name="proto"></param>
/// <param name="bind"></param>
/// <param name="manyToMany">多对多关系的中间实体类型</param>
/// <returns></returns>
public TableFluent<T> Navigate<TProto>(Expression<Func<T, TProto>> proto, string bind, Type manyToMany = null)
{
var member = (proto.Body as MemberExpression)?.Member;
if (member == null) throw new FormatException($"错误的表达式格式 {proto}");
var nav = new NavigateAttribute { Bind = bind, ManyToMany = manyToMany };
_table._navigates.AddOrUpdate(member.Name, nav, (name, old) => nav);
return this;
}
}
}