title: Entity Framework not using the right type for parameter
body: <p>I have a very simple example to demonstrate this issue.</p>
  
  <p>I have a Table Valued Function:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[TestTVF]
  (   
      @param1 varchar(max)
  )
  RETURNS TABLE 
  AS
  RETURN 
  (
      SELECT 1 as Id, 'Test' as [Name]
  )
  </code></pre>
  
  <p>And I have imported it into a edmx file:</p>
  
  <p><a href="https://i.stack.imgur.com/ONcOm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ONcOm.jpg" alt="enter image description here"></a></p>
  
  <p>But when I use the function the sql generate is this:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>This is just an example but in my real world scenario I need to pass in a large xml document that could be to up 300KB.</p>
  
  <p>How do I get Entity Framework to use nvarchar(max) and not nvarchar(4000)?</p>