Reputation: 3285
I am updating my existing mvc 3 app to an mvc 5 one. Using Vs2013. I just decided to create a new mvc 5 solution and simply copied over the folders with the views, models, business logic, pasted in the connection strings etc. However any which way (add existing files or include in project) I try to carry over the edmx file things go wrong. In the old project I have the edmx and the .tt and entities stacked/scoped under it. However when I add this to the new project the original structure falls apart and the tt files and poco classes are no longer stacked under the .edmx, not only that but I get renamed duplicates/copies of the context files and others e.g ModelContext1.cs in addition to ModelContext that is scoped under the ModelContext.tt file. How can I carry over the .edmx file and stacked structure intact with no duplicates ? Also if there is a way to stack the files back under the .edmx file manually, how can this be done ?
Upvotes: 1
Views: 3364
Reputation: 364389
Open the original .csproj for your old MVC3 application in text editor and search for XML elements referencing EDMX file, TT files and entity files. Your new .csproj for MVC5 application must follow exactly same structure with using:
DependentUpon
defining parent file in Solution ExplorerGenerator
defining tool used to process the file and generate codeLastGetOutput
the name of file generated by generator from current fileExample:
<ItemGroup>
<Compile Include="Model.Context.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Model.Context.tt</DependentUpon>
</Compile>
<Compile Include="Model.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Model.tt</DependentUpon>
</Compile>
<Compile Include="Model.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Model.edmx</DependentUpon>
</Compile>
<Compile Include="TestEntity.cs">
<DependentUpon>Model.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EntityDeploy Include="Model.edmx">
<Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Model.Designer.cs</LastGenOutput>
</EntityDeploy>
<None Include="Model.Context.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<DependentUpon>Model.edmx</DependentUpon>
<LastGenOutput>Model.Context.cs</LastGenOutput>
</None>
<None Include="Model.edmx.diagram">
<DependentUpon>Model.edmx</DependentUpon>
</None>
<None Include="Model.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<DependentUpon>Model.edmx</DependentUpon>
<LastGenOutput>Model.cs</LastGenOutput>
</None>
</ItemGroup>
Anyway your classes are auto-generated so you don't need to add them. You can generate them again in the new project. If you didn't change TT files you most probably don't need to add them manually - just use Add Generator item from the designer.
Upvotes: 1