public HasIndexFluent HasIndex(Expression <Func <T, object> > index) { var exp = index?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("index")); } var indexName = $"idx_{Guid.NewGuid().ToString("N").Substring(0, 8)}"; var columns = new List <string>(); switch (exp.NodeType) { case ExpressionType.MemberAccess: columns.Add((exp as MemberExpression).Member.Name); break; case ExpressionType.New: foreach (var member in (exp as NewExpression).Members) { columns.Add(member.Name); } break; } _tf.Index(indexName, string.Join(", ", columns), false); return(new HasIndexFluent(_tf, indexName, columns)); }
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 EfCoreTableFluent <T> HasKey(Expression <Func <T, object> > key) { var exp = key?.Body; if (exp?.NodeType == ExpressionType.Convert) { exp = (exp as UnaryExpression)?.Operand; } if (exp == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("key")); } switch (exp.NodeType) { case ExpressionType.MemberAccess: _tf.Property((exp as MemberExpression).Member.Name).IsPrimary(true); break; case ExpressionType.New: foreach (var member in (exp as NewExpression).Members) { _tf.Property(member.Name).IsPrimary(true); } break; } 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 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 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 <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 HasOneFluent HasOne(string one) { if (string.IsNullOrEmpty(one)) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one")); } if (_entityType.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one)); } return(new HasOneFluent(_fsql, _tf, _entityType, oneProperty.PropertyType, one)); }
public EfCoreTableFluent HasKey(string key) { if (key == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("key")); } foreach (string name in key.Split(',')) { if (string.IsNullOrEmpty(name.Trim())) { continue; } _tf.Property(name.Trim()).IsPrimary(true); } return(this); }
public HasManyFluent HasMany(string many) { if (string.IsNullOrEmpty(many)) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many")); } if (_entityType.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)); } return(new HasManyFluent(_fsql, _tf, _entityType, manyProperty.PropertyType.GetGenericArguments()[0], manyProperty.Name)); }
public HasOneFluent WithMany(string many) { if (many == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many")); } if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(many)); } _withManyProperty = manyProperty.Name; if (string.IsNullOrEmpty(_selfBind) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(many, _selfBind)); } 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 HasIndexFluent HasIndex(string index) { if (index == null) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("index")); } var indexName = $"idx_{Guid.NewGuid().ToString("N").Substring(0, 8)}"; var columns = new List <string>(); foreach (string name in index.Split(',')) { if (string.IsNullOrEmpty(name.Trim())) { continue; } columns.Add(name.Trim()); } _tf.Index(indexName, string.Join(", ", columns), false); return(new HasIndexFluent(_tf, indexName, columns)); }
public HasManyFluent WithOne(string one) { if (string.IsNullOrEmpty(one)) { throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one")); } if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one)); } if (oneProperty.PropertyType != _entityType1) { throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one)); } _withOneProperty = oneProperty.Name; if (string.IsNullOrEmpty(_selfBind) == false) { _fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(oneProperty.Name, _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 ParameterError_CannotBeNullTest() { string text = DbContextStrings.ParameterError_CannotBeNull("1"); output.WriteLine(text); }