private static void buildConfigureCommandMethodForStreamState(EventGraph graph, GeneratedType streamQueryHandlerType) { var sql = $"select id, version, type, timestamp, created as timestamp, is_archived from {graph.DatabaseSchemaName}.mt_streams where id = ?"; if (graph.TenancyStyle == TenancyStyle.Conjoined) { streamQueryHandlerType.AllInjectedFields.Add(new InjectedField(typeof(string), "tenantId")); sql += $" and {TenantIdColumn.Name} = ?"; } var setter = streamQueryHandlerType.AddStringConstant("SQL", sql); var configureCommand = streamQueryHandlerType.MethodFor("ConfigureCommand"); configureCommand.Frames.Call <CommandBuilder>(x => x.AppendWithParameters(""), call => { call.Arguments[0] = setter; call.ReturnAction = ReturnAction.Initialize; }); var idDbType = graph.StreamIdentity == StreamIdentity.AsGuid ? DbType.Guid : DbType.String; configureCommand.Frames.Code("{0}[0].Value = _streamId;", Use.Type <NpgsqlParameter[]>()); configureCommand.Frames.Code("{0}[0].DbType = {1};", Use.Type <NpgsqlParameter[]>(), idDbType); if (graph.TenancyStyle == TenancyStyle.Conjoined) { configureCommand.Frames.Code("{0}[1].Value = _tenantId;", Use.Type <NpgsqlParameter[]>()); configureCommand.Frames.Code("{0}[1].DbType = {1};", Use.Type <NpgsqlParameter[]>(), DbType.String); } }