Reputation: 277
Have an Asp.net core 1.1 Mvc app that I converted to 2.0 that includes a custom Templates/ folder. When I attempt to add a controller w EF actions, I get the following error:
I assume there are updated templates for core 2.0 but don't know where to find them.
Upvotes: 0
Views: 277
Reputation: 15209
Make the following modifications:
Templates\ControllerGenerator\MvcControllerWithContext.cshtml
Add :
@using System.Collections.Generic;
@using System.Linq;
in addition of :
using System.Collections.Generic;
using System.Linq;
So the 'header' looks like :
@inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
@using System.Collections.Generic;
@using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
Templates\ViewGenerator\List.cshtml
Add :
@using System.Collections.Generic;
@using System.Linq;
so the 'header' looks like :
@inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
@using Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
@using System.Collections.Generic
@using System.Linq
@@model @GetEnumerableTypeExpression(Model.ViewDataTypeName)
Then make the following replacement :
IEnumerable<PropertyMetadata> var properties = Model.ModelMetadata.Properties;
Sources:
https://forums.asp.net/p/2128119/6164188.aspx?Re+Migration+1+1+to+2+0+Scaffold+multiple+problems
https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/
Upvotes: 1