public void Build(DbCommandBuilder builder, IServiceProvider serviceProvider) { var environmentOption = serviceProvider.GetRequiredService <EnvironmentOption>(); builder.SqlBuilder.WriteLine("(values"); for (var i = 0; i < values.Count; ++i) { builder.SqlBuilder.Write("("); RoscoeExpressionVisitor.BuildAndConvert(values[i], builder, serviceProvider, !environmentOption.IsSubQuery); builder.SqlBuilder.Write(")"); if (i < values.Count - 1) { builder.SqlBuilder.Write(", "); } } builder.SqlBuilder.WriteLine(") as "); builder.SqlBuilder.WriteLine(alias); builder.SqlBuilder.WriteLine(" ("); // todo: builder.SqlBuilder.WriteLine(")"); }
public void Build(DbCommandBuilder builder, IServiceProvider serviceProvider) { if (Expression != null) { if (!(Expression.Body is NewExpression)) { throw new InvalidOperationException("Returning expression must create a new object"); } builder.SqlBuilder.Write("returning "); var aliasOption = serviceProvider.GetRequiredService <AliasOption>(); var aliasOptionClone = aliasOption.Clone(); aliasOption.EmitTable = true; ConvertExpression = RoscoeExpressionVisitor.BuildAndConvert(Expression, builder, serviceProvider, false); aliasOption.Restore(aliasOptionClone); //var json = JsonConvert.DeserializeObject<JToken>(JsonConvert.SerializeObject(new { Id = Guid.NewGuid(), Name = "Org name" })); //var result = ConvertExpression.Compile().Invoke(json); //builder.SqlBuilder.Write("))"); } }