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 HasManyFluent <T2> WithOne(Expression <Func <T2, T> > one) { var exp = one?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one")); } switch (exp.NodeType) { case ExpressionType.MemberAccess: _withOneProperty = (exp as MemberExpression).Member.Name; break; } if (string.IsNullOrEmpty(_withOneProperty)) { throw new ArgumentException(DbContextStrings.ParameterError("one")); } if (string.IsNullOrEmpty(_selfBind) == false) { _fsql.CodeFirst.ConfigEntity <T2>(eb2 => eb2.Navigate(_withOneProperty, _selfBind)); } return(this); }
public HasManyFluent <T2> HasMany <T2>(Expression <Func <T, IEnumerable <T2> > > many) { var exp = many?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many")); } var manyProperty = ""; switch (exp.NodeType) { case ExpressionType.MemberAccess: manyProperty = (exp as MemberExpression).Member.Name; break; } if (string.IsNullOrEmpty(manyProperty)) { throw new ArgumentException(DbContextStrings.ParameterError("many")); } return(new HasManyFluent <T2>(_fsql, _tf, manyProperty)); }
public HasOneFluent <T2> WithOne(Expression <Func <T2, T> > one, Expression <Func <T2, object> > foreignKey) { var exp = one?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one")); } switch (exp.NodeType) { case ExpressionType.MemberAccess: _withOneProperty = (exp as MemberExpression).Member.Name; break; } if (string.IsNullOrEmpty(_withOneProperty)) { throw new ArgumentException(DbContextStrings.ParameterError("one")); } 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: _withOneBind = (exp as MemberExpression).Member.Name; _withOneBind = _withOneBind.TrimStart(',', ' '); break; case ExpressionType.New: _withOneBind = ""; foreach (var member in (exp as NewExpression).Members) { _withOneBind += ", " + member.Name; } _withOneBind = _withOneBind.TrimStart(',', ' '); break; } if (string.IsNullOrEmpty(_withOneBind)) { throw new ArgumentException(DbContextStrings.ParameterError("foreignKey")); } if (string.IsNullOrEmpty(_selfBind) == false) { _fsql.CodeFirst.ConfigEntity <T2>(eb2 => eb2.Navigate(_withOneProperty, _withOneBind)); } return(this); }
public HasManyFluent 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(_withOneProperty) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withOneProperty, _selfBind)); } return(this); }
public HasOneFluent WithOne(string one, string foreignKey) { if (string.IsNullOrEmpty(one)) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one")); } if (_entityType1.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one)); } if (oneProperty != _entityType1) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one)); } _withOneProperty = oneProperty.Name; if (foreignKey == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey")); } foreach (string name in foreignKey.Split(',')) { if (string.IsNullOrEmpty(name.Trim())) { continue; } _withOneBind += ", " + name.Trim(); } if (string.IsNullOrEmpty(_withOneBind)) { throw new ArgumentException(DbContextStrings.ParameterError("foreignKey")); } _withOneBind = _withOneBind.TrimStart(',', ' '); if (string.IsNullOrEmpty(_selfBind) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withOneProperty, _withOneBind)); } return(this); }
public void ParameterErrorTest() { string text = DbContextStrings.ParameterError("1"); output.WriteLine(text); }