title: LINQ to SQL generate "null" instead of "not null" from sql server function "return table as"
body: <p>I'm working with SQL Server Express 2012 with advance services and Visual Studio 2013 update 2. I have simplified the example to the core. I have the following table in my database:</p>
  
  <pre><code>CREATE TABLE [dbo].[Realty]
  (
  [Id] [int] IDENTITY(1,1) NOT NULL,
  ...
  ...
  [RankingBonus] [int] NOT NULL,
  [Ranking]  AS ([Id]+[RankingBonus]) PERSISTED NOT NULL,
  ...
  )
  </code></pre>
  
  <p>Having fulltext table function over this table:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[GetFilteredRealtyFulltext]
  (@fulltextcriteria nvarchar(4000))
  RETURNS TABLE
  AS
  RETURN (SELECT 
  realty.Id AS realtyId,
  ...
  realty.Ranking, --THIS IS IMPORTANT FOR THE QUIESTION!
  ...,
  ( COALESCE(ftR.Rank,0) + COALESCE(ftObec.Rank,0) + COALESCE(ftOkres.Rank,0) + COALESCE(ftpobvod.Rank,0)) AS FtRank
  
  FROM realty
  --these joins and where conditions are not important for this stackoverflow question
  --this only shows why I use table function with return table
  --it is because this is the only way I found how to generate LINQ to SQL with fulltext as IQueryable&lt;T&gt;
  JOIN Category ON realty.CategoryId = Category.Id
  LEFT JOIN ruian_cobce ON realty.cobceId = ruian_cobce.cobce_kod
  LEFT JOIN ruian_obec ON realty.obecId = ruian_obec.obec_kod
  LEFT JOIN okres ON realty.okresId = okres.okres_kod
  LEFT JOIN ExternFile ON realty.Id = ExternFile.ForeignId AND ExternFile.IsMain = 1 AND ExternFile.ForeignTable = 5
  INNER JOIN Person ON realty.OwnerId = Person.Id
  Left JOIN CONTAINSTABLE(Realty, *, @fulltextcriteria) ftR ON realty.Id = ftR.[Key] 
  Left JOIN CONTAINSTABLE(ruian_obec, *, @fulltextcriteria) ftObec ON realty.obecId = ftObec.[Key] 
  Left JOIN CONTAINSTABLE(Okres, *, @fulltextcriteria) ftOkres ON realty.okresId = ftOkres.[Key]
  Left JOIN CONTAINSTABLE(pobvod, *, @fulltextcriteria) ftpobvod ON realty.pobvodId = ftpobvod.[Key]
  WHERE Person.ConfirmStatus = 1
  AND ( COALESCE(ftR.Rank,0) + COALESCE(ftObec.Rank,0) + COALESCE(ftOkres.Rank,0) + COALESCE(ftpobvod.Rank,0))  &gt; 0
  )
  GO
  </code></pre>
  
  <p>When I drop the function GetFilteredRealtyFulltext into DBML, the designer generate the column Ranking as <strong>Nullable int</strong></p>
  
  <pre><code>[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Ranking", DbType="Int")]
  public System.Nullable&lt;int&gt; Ranking
  {
    get
    {
      return this._Ranking;
    }
    set
    {
      if ((this._Ranking != value))
      {
         this._Ranking = value;
      }
    }
  }
  </code></pre>
  
  <p>I expect it should generate just <strong>integer</strong>:</p>
  
  <pre><code>[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Ranking", DbType="Int NOT NULL"")]
  public int Ranking
  {
    get
    {
      return this._Ranking;
    }
    set
    {
      if ((this._Ranking != value))
      {
         this._Ranking = value;
      }
    }
  }
  </code></pre>
  
  <p>The table Realty is generated correctly in DBML file, the Ranking is just integer, but the table function is generated incorrectly. What is wrong with it?</p>
  
  <p>UPDATE:</p>
  
  <p><a href="https://dba.stackexchange.com/questions/114260/why-sql-server-recognize-the-view-column-as-nullable-if-the-underlying-column-is">Linked question</a> going to the core of problem.</p>