0

I use Entity Framework 6 Database First with Visual Studio 2015. Sometimes when I modify .edmx diagram and save changes, all .cs class(for tables) are deleting from code generation model.tt file and I could not make these return. Just for create Entity Data Model from zero, too.

Anybody know what is the reason of this problem, end how should I solve this?

Thanks any helps.

I have modified my entity data model with this:(Not know it can be the reason or other)

*EF5 Grdiview only Count & ReadOnly /After that open yourModel.tt file Find and replace the two occurrences of “ICollection” with “ObservableListSource” (lines 296 and 484). Find and replace the first occurrence of “HashSet” with “ObservableListSource” ( Line 50). Do not replace the second occurrence of HashSet found later in the code./*

Community
  • 1
  • 1
iolah2
  • 13
  • 3
  • did you try to re build the project? Normal behavior is when you rebuild it should recreate the classes. – Seminda Dec 13 '16 at 23:31
  • I try rebuild and try delete .tt files, and recreate these, but problem stay. Maybe I should use code first from database or what? – iolah2 Dec 14 '16 at 07:10

2 Answers2

1

You are using database first approach and manually modifying .edmx hence the model is not able to locate corresponding mapping in the db tables. Try using model first approach if you want to manually make changes to .edmx, or try changing the db first and update you .edmx later.

Poonam
  • 153
  • 1
  • 12
0

If the classes are not being generated this means there is an error in the edmx file, try to open it, and validate it, you can validate by right click the edmx file and click validate.

As for the .tt file, right click and choose "Run Custom Tool" and see if the code gets generated or not.

Advice: Switch to Code First :)

Haitham Shaddad
  • 4,336
  • 2
  • 14
  • 19
  • I just modify edmx with add a new entitiy, that not have PK. My teacher said I should give a parent class for similar entities. Example NameTitle, Language, etc. The same in these just they have ID(NameTitleID, LanguageID), and a string(Description, with deferent lengths). When I think and an entity with this 2 prop and inheritance others from it, after happened this lost. But it were happened too, when I modify database, refresh from database and save edmx. ObservableListSource can be the reason, or what? – iolah2 Dec 14 '16 at 16:19
  • I am sorry, I find a great difficulty understanding your comment, you should not modify the edmx manually or change the generated code at all cause it will be lost whenever the code generator runs – Haitham Shaddad Dec 14 '16 at 18:42