0

In Entity Framework, I understand that if you make changes to the automatically created classes, you lose those chages on any kind of DB update. So, due to this you, only make your changes to these objects in a separate file using the Partial Class syntax.

In a similar way, I had to change my actual .edmx file manually to add in a defining query as was described to do here.

Now, when I go to add in new tables from the DB, some of the changes I made to the edmx file are lost and I start getting errors in my project.

Is there a way to do something similar with the edmx file? - Maybe create a second XML under the same namespace that would therefore append on at load-time? And, if so, are there any examples of how to do this? EF is brand new to me and beating me up much more than I thought it would :)

Thanks!!

John Bustos
  • 19,036
  • 17
  • 89
  • 151
  • DefiningQuery is more of a final solution- chances are there is something more flexible you can use to solve the problem you are solving with the DefiningQuery. Something that won't get lost every time you refresh your edmx – Nick Patsaris Jun 30 '14 at 16:13
  • @CircularReference, I had to sue it to answer this question I also posted on SO - http://stackoverflow.com/questions/24434646/entity-framework-5-db-first-association-on-a-non-primary-key-field-error?noredirect=1#comment37808813_24434646 - I would **LOVE** a more easily-implementable solution if you have any ideas!!! – John Bustos Jun 30 '14 at 17:48

2 Answers2

0

You can also create a partial class for your model main file. there is class with name yourmodel.Context.cs(vb). you can create another class out of model and make that class partial to this class, and do your customizations in partial class, otherwise you will loose all your customization on each model update.

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
  • 1
    Thanks, Vahid... I'm just a bit confused, though, since I'm making these changes in the actual XML version of the edmx file to put in things like the defining query... How could I do this with partial classes? Do you have any examples or anything?? – John Bustos Jun 30 '14 at 13:55
0

as you see in this picture [Click to see], I have a edmx file. inside this file I have a file named: xxxx.Context.vb
If you open this file you will see that for example its name is Entities and inherits from DbContext. this file is the main class in EF. you can create a partial class with this file class name and do your customization in it.

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62