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

Paramter Type is not right. #29

Open
jonantoine opened this issue Aug 27, 2018 · 2 comments
Open

Paramter Type is not right. #29

jonantoine opened this issue Aug 27, 2018 · 2 comments

Comments

@jonantoine
Copy link

I have a very simple example to demonstrate this issue.

I have a Table Valued Function:

CREATE FUNCTION [dbo].[TestTVF]
(	
    @param1 varchar(max)
)
RETURNS TABLE 
AS
RETURN 
(
    SELECT 1 as Id, 'Test' as [Name]
)

And I have the DbFunction

[DbFunction("DB", "TestTVF")]
public IQueryable<TestTvfResult> TestTVF([ParameterType(StoreType = "varchar(max)")] string param1)
{
    var p1 = param1 != null ?
        new ObjectParameter("param1", param1) :
        new ObjectParameter("param1", typeof(string));

    return ((IObjectContextAdapter)this).ObjectContext.
    CreateQuery<TestTvfResult>("[DB].[TestTVF](@param1)", p1);
}

But when I use the function the sql generate is this:

exec sp_executesql N'SELECT 
1 AS [C1], 
[Extent1].[Id] AS [Id], 
[Extent1].[Name] AS [Name]
FROM [dbo].[TestTVF](@param1) AS [Extent1]',N'@param1 nvarchar(4000)',@param1=N'test'

Expected: use varchar(max) and not nvarchar(4000)

@moozzyk
Copy link
Owner

moozzyk commented Aug 28, 2018

Thanks, I will need to take a look a this.

@moozzyk
Copy link
Owner

moozzyk commented Oct 25, 2018

FYI, I looked at this some time ago and it seems that the parameter type is passed to EF as specified in the attribute. The value is being lost somewhere in EF but I have not found yet where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants