public void WithMany(Expression <Func <T2, IEnumerable <T> > > many, Type middleType) { var exp = many?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many")); } switch (exp.NodeType) { case ExpressionType.MemberAccess: _withManyProperty = (exp as MemberExpression).Member.Name; break; } if (string.IsNullOrEmpty(_withManyProperty)) { throw new ArgumentException(DbContextStrings.ParameterError("many")); } _tf.Navigate(_selfProperty, null, middleType); _fsql.CodeFirst.ConfigEntity <T2>(eb2 => eb2.Navigate(_withManyProperty, null, middleType)); }
public HasOneFluent HasForeignKey(string foreignKey) { if (foreignKey == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey")); } foreach (string name in foreignKey.Split(',')) { if (string.IsNullOrEmpty(name.Trim())) { continue; } _selfBind += ", " + name.Trim(); } if (string.IsNullOrEmpty(_selfBind)) { throw new ArgumentException(DbContextStrings.ParameterError("foreignKey")); } _selfBind = _selfBind.TrimStart(',', ' '); _tf.Navigate(_selfProperty, _selfBind); if (string.IsNullOrEmpty(_withManyProperty) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withManyProperty, _selfBind)); } if (string.IsNullOrEmpty(_withOneProperty) == false && string.IsNullOrEmpty(_withOneBind) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withOneProperty, _withOneBind)); } return(this); }
public void WithMany(string many, Type middleType) { if (string.IsNullOrEmpty(many)) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many")); } if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_CollectionProperties(many)); } if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) { throw new ArgumentException(DbContextStrings.ParameterError_IsNot_CollectionProperties(many)); } _withManyProperty = manyProperty.Name; _tf.Navigate(_selfProperty, null, middleType); _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withManyProperty, null, middleType)); }
public void WithMany(string many, Type middleType) { if (string.IsNullOrEmpty(many)) { throw new ArgumentException("参数错误 many 不能为 null"); } if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) { throw new ArgumentException($"参数错误 {many} 集合属性不存在"); } if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) { throw new ArgumentException("参数错误 {many} 不是集合属性"); } _withManyProperty = manyProperty.Name; _tf.Navigate(_selfProperty, null, middleType); _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withManyProperty, null, middleType)); }
public void WithMany(Expression <Func <T2, IEnumerable <T> > > many, Type middleType) { if (many?.Body == null) { throw new ArgumentException("参数错误 many 不能为 null"); } var exp = many.Body; switch (exp.NodeType) { case ExpressionType.MemberAccess: _withManyProperty = (exp as MemberExpression).Member.Name; break; } if (string.IsNullOrEmpty(_withManyProperty)) { throw new ArgumentException("参数错误 many"); } _tf.Navigate(_selfProperty, null, middleType); _tf.ConfigEntity <T2>(eb2 => eb2.Navigate(_withManyProperty, null, middleType)); }
public HasOneFluent <T2> HasForeignKey(Expression <Func <T, object> > foreignKey) { var exp = foreignKey?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey")); } switch (exp.NodeType) { case ExpressionType.MemberAccess: _selfBind = (exp as MemberExpression).Member.Name; _selfBind = _selfBind.TrimStart(',', ' '); break; case ExpressionType.New: _selfBind = ""; foreach (var member in (exp as NewExpression).Members) { _selfBind += ", " + member.Name; } _selfBind = _selfBind.TrimStart(',', ' '); break; } if (string.IsNullOrEmpty(_selfBind)) { throw new ArgumentException(DbContextStrings.ParameterError("foreignKey")); } _tf.Navigate(_selfProperty, _selfBind); if (string.IsNullOrEmpty(_withManyProperty) == false) { _fsql.CodeFirst.ConfigEntity <T2>(eb2 => eb2.Navigate(_withManyProperty, _selfBind)); } if (string.IsNullOrEmpty(_withOneProperty) == false && string.IsNullOrEmpty(_withOneBind) == false) { _fsql.CodeFirst.ConfigEntity <T2>(eb2 => eb2.Navigate(_withOneProperty, _withOneBind)); } return(this); }
public HasOneFluent <T2> HasForeignKey(Expression <Func <T, object> > foreignKey) { if (foreignKey?.Body == null) { throw new ArgumentException("参数错误 foreignKey 不能为 null"); } var exp = foreignKey.Body; switch (exp.NodeType) { case ExpressionType.MemberAccess: _selfBind = (exp as MemberExpression).Member.Name; _selfBind = _selfBind.TrimStart(',', ' '); break; case ExpressionType.New: _selfBind = ""; foreach (var member in (exp as NewExpression).Members) { _selfBind += ", " + member.Name; } _selfBind = _selfBind.TrimStart(',', ' '); break; } if (string.IsNullOrEmpty(_selfBind)) { throw new ArgumentException("参数错误 foreignKey"); } _tf.Navigate(_selfProperty, _selfBind); if (string.IsNullOrEmpty(_withManyProperty) == false) { _tf.ConfigEntity <T2>(eb2 => eb2.Navigate(_withManyProperty, _selfBind)); } if (string.IsNullOrEmpty(_withOneProperty) == false && string.IsNullOrEmpty(_withOneBind) == false) { _tf.ConfigEntity <T2>(eb2 => eb2.Navigate(_withOneProperty, _withOneBind)); } return(this); }