title: EF6 Model First: schema specified is not valid, error 0040
body: <p>I see that this question has been asked quite a bit, but none of the solutions have helped me since I'm using model first and not code first.</p>
  
  <p>I have a C# project in VS 2015 using EF6.  I am building a database using the model first approach and can successfully generate the SQL code from the model and run it in SSMS.  I'm using SQL Server LocalDB.</p>
  
  <p>The problem I have is that whenever I try to add a programmatically created entity to the collection (table) to which it belongs, I always get the error</p>
  
  <p><em>An exception of type 'System.Data.Entity.Core.MetadataException' occurred in mscorlib.dll but was not handled in user code</em></p>
  
  <p><em>Additional information: Schema specified is not valid.</em></p>
  
  <p><em>Errors: 
  Market.ssdl(184,6) : error 0040: The Type nvarchar(max) is not qualified with a namespace or alias. Only primitive types can be used without qualification.</em></p>
  
  <p>The entity I'm creating is has only one property; a string (or nvarchar(max) in the database).  Again, I can create the object, but the moment I try to add it to its collection (or table) before saving any changes, I get the above error.  I even tried not naming the Name property, but the error persists.</p>
  
  <p><code>using (var context = new MarketContainer())
      {
          // Create data source
          var datasource = new DataSource()
          {
              Name = dataSourceName
          };
          // Save data source
          context.DataSources.Add(datasource);
      }</code></p>
  
  <p>Another SO answer proposed to right click on the .tt file and clicking "Run Custom Tool", but that didn't do anything.</p>
  
  <p>I tried this once with MySQL and it worked fine! Now that I need to move to SQL Server it doesn't work...  I've been stuck on this problem for over a week, so really any help would go a long way.</p>