0

For some reasons we need to update Views inside the Entity Framework. So we followed this solution on another question and it worked like a charm!

BUT here is the problem:
if we update our model (for some new fields or tables/views) the complete Mappings are destroyed and after updating we get the Warning

Error 11007: Entity type 'UpdateView1' is not mapped.

After this it's not even possible to load the entities because all Mappings are lost.
So how to design the views to be able to post updates using the Views AND to be able to update the edmx file?

Community
  • 1
  • 1
Obl Tobl
  • 5,604
  • 8
  • 41
  • 65
  • MS doesn't even like edmx files. They are dropping it from EF moving forward. Switch to Code First. – Sam Axe Aug 07 '15 at 06:55
  • It's not possible to use Code First, the database is really old and really big... – Obl Tobl Aug 07 '15 at 06:57
  • What do you mean for "Model"? Are you trying to add a column to db, the reload, then update the class? – Francesco De Lisi Aug 07 '15 at 06:58
  • 1
    That's a common misconception due to the feature name. Code First doesn't mean you have to start with code. You can start with the database and then write your POCOs to match it (as in your case). Doing so allows you to preserve all your mappings and such because you just adjust your code to match the structure already present in your database. – Sam Axe Aug 07 '15 at 06:59
  • @FDL yes exactly, from time to time it's possible that we need new fields in the database. When we then upate the Model/edmx-File, all Mappings get lost. – Obl Tobl Aug 07 '15 at 07:00
  • @SamAxe you are right, if this works i misunderstood the Code First approach. I will have a look at this! – Obl Tobl Aug 07 '15 at 07:03
  • What happens if you delete the Table/View and then update the model from the database? Does it re-create the Entity? – Francesco De Lisi Aug 07 '15 at 07:18
  • @SamAxe If you post your Comment as an answer, i will accept it! Helped me a lot, thank you! – Obl Tobl Aug 07 '15 at 08:28
  • @OblTobl: I'm glad it helped. – Sam Axe Aug 07 '15 at 23:27

1 Answers1

2

MS is dropping support for EDMX files going forward in Entity Framework - in part due to the difficulty of keeping the database, EDMX, and POCOs all sync'd, as you are experiencing. (Anyone can edit any of the 3, then changes are lost when a sync is done).

So they recommend using the Code First approach. Code First is a bit of a misnomer and causes some confusion.

Code First doesn't mean you have to start with code.
You can start with the database and then write your POCOs to match it (as in your case). Doing so allows you to preserve all your mappings and such because you just adjust your code to match the structure already present in your database.

Another misconception is that you have to use migrations. You do not. You are welcome to not enable migrations and manually edit both the database schema and POCOs as long as you ensure they remain in sync.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89