piris
piris

Reputation: 1595

Entity Framework - Views vs Tables

I'm using Entity Framework 6 in my ASP.NET MVC project using database first approach.... I have an .edmx file with all the table associations.

Now, the sql developers do not want to have any direct calls to the tables, so they would like me to use views instead.

I'm trying to understand what are the benefits of using Views vs Tables?

Also, I'm afraid if I use Views and apply all the PK and FK in the edmx and i regenerate something the changes will be lost?

Any thoughts on this please?

Upvotes: 4

Views: 7821

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239290

Your SQL developers are idiots. Please feel free to tell them so. The only thing using a view of a table does versus the using the table directly is disallow write operations. If that's the goal, there's better ways to achieve that by doing things as simple as just having the application use a user without write privileges.

By using views, you're forgoing primary keys, foreign keys and indexing, all of which serve to make queries more performant. In other words, your SQL developers are asking you to hit the database harder and make less performant queries against it. In other words, they have no idea what they're talking about.

If the application needs writes (which frankly there's very few applications that don't), then views are out anyways. If they're really all that concerned about Entity Framework making writes, then they can also create stored procedures for tasks like CREATE, UPDATE, etc. and you can integrate those stored procedures into Entity Framework. However, I can almost assure you that Entity Framework is generating better SQL than they can write by hand, if for no other reason than it's being used and contributed to by far many more people than you have on staff.

Upvotes: 7

Related Questions