10

Hasty research tells me that even EF4 still doesn't support SQL Server synonyms. What are my options for setting up a synonym based entity set as if it were a table based entity set? The crudest I have come up with is to copy the underlying table for the synonym, add it to my model, and then rename the entity set in the store model. Is there no more elegant workaround using the POCO or code-first approach?

ProfK
  • 49,207
  • 121
  • 399
  • 775

2 Answers2

8

You could create a view that selects data from your synonym and then add the view to your model. Giving the view in your model the name of the synonym.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • To add to this, EF supports using stored procedures for insert, update, and delete operations. We've used that approach in a dynamic data app that displayed view data for editing. – Brian Mains Jun 30 '14 at 13:24
  • 1
    @zsong: If the view consists of one table, then you can insert/update it. I found and used this technique today, works like a champ. +1 (Edit: 6.5 years later) – Derreck Dean Dec 07 '17 at 05:15
4

See this post - apparently you can do it with some manual manipulation of the edmx.

Making an Entity Framework Model span multiple databases

It's not elegant, though, so it doesn't answer your question :-)

Community
  • 1
  • 1
camainc
  • 3,750
  • 7
  • 35
  • 46