Reputation: 5083
Is it possible to map an entity to a database view using code-first?
Upvotes: 2
Views: 1056
Reputation: 5083
Instead of adding a view, an alternative is to call a stored procedure using the DbContext class.
_context.Database.SqlQuery<Model>("spTest").ToList();
Upvotes: 0
Reputation: 15130
Yes you can. You have to construct the View manually however. This can be done using a custom database initializer. Then you can just map an entity to a view since the underlying SQL syntax is the same. See: http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/f154595c-717e-4703-a81d-ee63633a481e
EDIT as Merlyn Morgan-Graham points out, this is a duplicate to Is it possible to add a view in code-first context?
Upvotes: 1