0

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?

MaMu
  • 1,837
  • 4
  • 20
  • 36
  • On the Designer properties, is 'Code Generation Strategy' set to 'Default'? – GrandMasterFlush Dec 11 '12 at 15:56
  • No, it wasn't. I have tried to change it, but the tables are still not generated and 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'. – MaMu Dec 11 '12 at 16:05
  • What are the errors? Edit your question and put a few examples of them in. – GrandMasterFlush Dec 11 '12 at 16:06
  • Okay, did you create the classes for the existing tables before you added the new ones? If you, or someone else, has manually created some of the classes and then you've added new tables and then set the Code Generation Strategy it could be that VS is trying to generate the classes for tables that have already been created. – GrandMasterFlush Dec 11 '12 at 16:20
  • No, I haven't created anything manually. If, then only in model, that was deleted long time ago. – MaMu Dec 11 '12 at 16:33
  • In the error message above, what are DPR_MM and DPR_TS? – GrandMasterFlush Dec 11 '12 at 16:37
  • 1
    @Mamu: If you are using VS2012 and changed the code generation strategy to Default (from None) but did not delete tt files under edmx your entities are being generated twice. Either remove tt files or set the code generation strategy to None – Pawel Dec 11 '12 at 17:41
  • @Pawel as have already writtten I have removed the whole model . – MaMu Dec 12 '12 at 13:27
  • delete your Model1.edmx - the links I gave in my answer state that you cannot have multiple models pointing to the same table/column – Mario Dec 12 '12 at 15:36

1 Answers1

0

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:

public partial class DPR_MM : EntityObject
{
    public global::System.Int32 DPR_TS
    {
    ...
    }
}

public partial class DPR_MM : EntityObject
{
    //maybe code generation fails because it doesn't want to do this a second time knowing it would be ambiguous 
    public global::System.Int32 DPR_TS  
    {
    ...
    }
}

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")

Community
  • 1
  • 1
Mario
  • 3,405
  • 6
  • 38
  • 48
  • I did - the new tables are not there. Now I have also tried with selected tables. No luck. – MaMu Dec 11 '12 at 15:55
  • Sorry, thought that would be it. Don't have VS 2012 at work yet or else I would check, though you should be able to look at YourModel.designer.cs under YourModel.edmx and see the actual class. Verify the class is there that matches the table you added, that you have no errors in your project and do a clean and a rebuild. – Mario Dec 11 '12 at 16:13
  • NP! BTW: I wrote, that I have rebuilt the solution w/o any luck! – MaMu Dec 11 '12 at 16:15
  • 1
    If that doesn't work I would start over by deleting your model and readding it. It only takes a minute or so and may be easier than troubleshooting weird errors – Mario Dec 11 '12 at 16:16
  • Yes, you are right. But this is still really annoying imho... :oS! – MaMu Dec 11 '12 at 16:23
  • No, now I cant rebuild it. It worse now, cause I have no classes at all. – MaMu Dec 11 '12 at 16:34
  • I have already written it... I have removed the whole model. You can see my edited question. – MaMu Dec 12 '12 at 13:31