mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 增加 NavigateAttribute 特性对应的 Fluent 功能;#96
This commit is contained in:
		@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user