Skip to content
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

Query: Preserve Schema in SqlFunctionExpression while visiting children #10423

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public virtual void String_Like_Literal_With_Escape()
using (var context = CreateContext())
{
var count = context.Customers.Count(c => EF.Functions.Like(c.ContactName, "!%", "!"));

Assert.Equal(0, count);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public string DollarValueInstance(int starCount, string value)
throw new NotImplementedException();
}

[DbFunction(Schema = "dbo")]
public static string IdentityString(string s)
{
throw new NotImplementedException();
}

#endregion

public UDFSqlContext(DbContextOptions options)
Expand Down Expand Up @@ -855,6 +861,25 @@ FROM [Customers] AS [c]
}
}

[Fact]
public void Nullable_navigation_property_access_preserves_schema_for_sql_function()
{
using (var context = CreateContext())
{
var result = context.Orders
.OrderBy(o => o.Id)
.Select(o => UDFSqlContext.IdentityString(o.Customer.FirstName))
.FirstOrDefault();

Assert.Equal("Customer", result);
AssertSql(
@"SELECT TOP(1) [dbo].IdentityString([o.Customer].[FirstName])
FROM [Orders] AS [o]
LEFT JOIN [Customers] AS [o.Customer] ON [o].[CustomerId] = [o.Customer].[Id]
ORDER BY [o].[Id]");
}
}

#endregion

#region Instance
Expand Down Expand Up @@ -1571,6 +1596,13 @@ returns bit
return 0
end");

context.Database.ExecuteSqlCommand(@"create function [dbo].[IdentityString] (@customerName nvarchar(max))
returns nvarchar(max)
as
begin
return @customerName;
end");

var order11 = new Order { Name = "Order11", ItemCount = 4, OrderDate = new DateTime(2000, 1, 20) };
var order12 = new Order { Name = "Order12", ItemCount = 8, OrderDate = new DateTime(2000, 2, 21) };
var order13 = new Order { Name = "Order13", ItemCount = 15, OrderDate = new DateTime(2000, 3, 20) };
Expand Down