Skip to content

No extra newline between query tags #32104

@breakfast-with-kevin

Description

@breakfast-with-kevin

Per the documentation when you use multiple TagWith calls it is supposed to put an extra newline without comment marks (--) between them. The actual behavior is that is does not include a newline, making it impossible to parse tags unless you can assume that none of them are multiline.

Test Case:

var test = db.MyEntity
		.TagWith("Test 1")
		.TagWith(@"Test
2")
		.ToArray();

Expected:

-- Test 1

-- Test
-- 2

SELECT [m].[Value] FROM [dbo].[MyEntity] AS [m]

Actual:

-- Test 1
-- Test
-- 2

SELECT [m].[Value] FROM [dbo].[MyEntity] AS [m]

Also, I would like to submit a request to add a parsed collection of tags to the CommandEndEventData. It could be added with a method similar to this (assuming the above bug is fixed).

IEnumerable<string> ParseTags(string script)
        {
            var sb = new StringBuilder();
            var writingTag = false;

            foreach (var line in script.Split(Environment.NewLine))
            {
                if (line.StartsWith("-- "))
                {
                    writingTag = true;
                    sb.AppendLine(line[3..]);
                    continue;
                }

                if (writingTag)
                {
                    writingTag = false;
                    yield return sb.ToString();
                    sb.Clear();
                    continue;
                }

                break;
            }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions