-
Notifications
You must be signed in to change notification settings - Fork 53
Translate 'case when X is null...' to 'coalesce(X,...)' #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -772,5 +772,67 @@ public void TestTableValuedStoredFunctions() | |
Assert.AreEqual(1, list2[0].Something); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Test_issue_60_and_62() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test needs a better name, maybe: Test_string_type_inference_in_coalesce_statements |
||
{ | ||
using (var context = new BloggingContext(ConnectionString)) | ||
{ | ||
context.Database.Log = Console.Out.WriteLine; | ||
|
||
context.Blogs.Add( new Blog { Name = "Hello" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Extra space before new keyword. |
||
context.SaveChanges(); | ||
|
||
string stringValue = "string_value"; | ||
var query = context.Blogs.Select(b => stringValue + "_postfix"); | ||
var blogTitle = query.First(); | ||
Assert.That(blogTitle, Is.EqualTo("string_value_postfix")); | ||
Console.WriteLine(query.ToString()); | ||
StringAssert.AreEqualIgnoringCase("SELECT COALESCE( @p__linq__0,E'') || E'_postfix' AS \"C1\" FROM \"dbo\".\"Blogs\" AS \"Extent1\"", query.ToString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readability: This line is too long and is hard to read for other developers, break it at sensible points into 2 or more strings concatenated with "+" so that the length of each line is as near in length to surrounding code. Also there is extra spaces around COALESCE statement. You don't have to add these spaces in the expression. The parsing system automatically handles that. |
||
} | ||
} | ||
|
||
[Test] | ||
public void TestNullPropagation_1() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test needs a better name, maybe: Test_string_null_propagation |
||
{ | ||
using (var context = new BloggingContext(ConnectionString)) | ||
{ | ||
context.Database.Log = Console.Out.WriteLine; | ||
|
||
context.Blogs.Add( new Blog { Name = "Hello" }); | ||
context.SaveChanges(); | ||
|
||
string stringValue = "string_value"; | ||
var query = context.Blogs.Select(b => (stringValue ?? "default_value") + "_postfix"); | ||
var blog_title = query.First(); | ||
Assert.That(blog_title, Is.EqualTo("string_value_postfix")); | ||
|
||
Console.WriteLine(query.ToString()); | ||
StringAssert.AreEqualIgnoringCase("SELECT CASE WHEN ( COALESCE( @p__linq__0,E'default_value') IS NULL) THEN (E'') WHEN (@p__linq__0 IS NULL) THEN (E'default_value') ELSE (@p__linq__0) END || E'_postfix' AS \"C1\" FROM \"dbo\".\"Blogs\" AS \"Extent1\"", query.ToString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readability: This line is too long and is hard to read for other developers, break it at sensible points into 2 or more strings concatenated with "+" so that the length of each line is as near in length to surrounding code. |
||
} | ||
} | ||
|
||
[Test] | ||
public void TestNullPropagation_2() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test needs a better name, maybe: Test_string_multiple_null_propagation |
||
{ | ||
using (var context = new BloggingContext(ConnectionString)) | ||
{ | ||
context.Database.Log = Console.Out.WriteLine; | ||
|
||
context.Blogs.Add( new Blog { Name = "Hello" }); | ||
context.SaveChanges(); | ||
|
||
string stringValue1 = "string_value1"; | ||
string stringValue2 = "string_value2"; | ||
string stringValue3 = "string_value3"; | ||
|
||
var query = context.Blogs.Select(b => (stringValue1 ?? stringValue2 ?? stringValue3) + "_postfix"); | ||
var blog_title = query.First(); | ||
Assert.That(blog_title, Is.EqualTo("string_value1_postfix")); | ||
|
||
Console.WriteLine(query.ToString()); | ||
StringAssert.AreEqualIgnoringCase("SELECT CASE WHEN ( COALESCE( @p__linq__0, COALESCE( @p__linq__1,@p__linq__2) ) IS NULL) THEN (E'') WHEN (@p__linq__0 IS NULL) THEN ( COALESCE( @p__linq__1,@p__linq__2) ) ELSE (@p__linq__0) END || E'_postfix' AS \"C1\" FROM \"dbo\".\"Blogs\" AS \"Extent1\"", query.ToString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readability: This line is too long and is hard to read for other developers, break it at sensible points into 2 or more strings concatenated with "+" so that the length of each line is as near in length to surrounding code. |
||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for extra space before and after the coalesce statement.