I 'm using Visual Studio and working on an app based on MVC. I'm trying to add some tables to my model. I have used option "Update model from database". The new tables appeared in my edmx file. I have rebuilt my solution but the classes for new tables are missing. Is there any trick to generate the classes every time i wanna add new tables? Or do i have to do it manually?
When I set 'Code Generation Strategy' to 'Default' I'm getting hundred of errors similar to this one Error 117 The type 'Mvc4.Models.DPR_MM' already contains a definition for 'DPR_TS'
.
I have removed the whole Model. While searching the whole solution for DPR_MM
I'm getting these results:
Find all "DPR_MM", Subfolders, Find Results 1, Entire Solution, ""
C:\\Mvc4\Controllers\HomeController.cs(41): var DPR_MM = from d in ctx.DPR_MM
C:\\Mvc4\Controllers\HomeController.cs(45): var arr = new object[DPR_MM.Count()];
C:\\Mvc4\Controllers\HomeController.cs(47): foreach (var d in DPR_MM)
C:\\Mvc4\Models\Model1.edmx(9): <EntitySet Name="DPR_MM" EntityType="Model.Store.DPR_MM" store:Type="Tables" Schema="QF" />
C:\\Mvc4\Models\Model1.edmx(45): <EntityType Name="DPR_MM">
C:\\Mvc4\Models\Model1.edmx(366): <EntitySet Name="DPR_MM" EntityType="Model.DPR_MM" />
C:\\Mvc4\Models\Model1.edmx(389): <EntityType Name="DPR_MM">
C:\\Mvc4\Models\Model1.edmx(715): <EntitySetMapping Name="DPR_MM">
C:\\Mvc4\Models\Model1.edmx(716): <EntityTypeMapping TypeName="Model.DPR_MM">
C:\\Mvc4\Models\Model1.edmx(717): <MappingFragment StoreEntitySet="DPR_MM">
C:\\Mvc4\Models\Model1.edmx.diagram(8): <EntityTypeShape EntityType="Model.DPR_MM" Width="1.5" PointX="0.75" PointY="0.75" IsExpanded="true" />
Matching lines: 11 Matching files: 3 Total files searched: 168
So I don't see any DPR_MM class. What I am doing wrong?
Edit
Now that I know you are getting an error, look at the generated code (you could even do a solution search for your class DPR_MM to find all instances of this class). I would guess you have a class Mvc4.Models.DPR_MM in your project that already has DPR_TS as a member and code generation sees that and won't generate another one, kind of like the following:
You should always be able to generate a new model unless there is some database or namespace problem so make sure you don't have extra files laying around like @Mamu says. Or you could just google it:
first hit
another answer
Initial answer
Do a build. You should then see all your new classes based on the tables you selected when you "updated model from database" (obviously you have to select the new tables when "updating model from database")