Creating Entity Framework Objects from Stored Procedures

When using Entity Framework 4, how do you create a single entity from a stored procedure?


After you add the stored procedure to the model, from the Model Browser right-click the stored procedure under the Store node and select 'Add Function Import'. In that dialog, indicate what entity should be created:

You can then use that stored procedure like this:

Artist a = ctx.SelectArtist(id).SingleOrDefault();


Based on the comments, it sounds like you want to use stored procedures to perform inserts, updates, and deletes. If you right-click on the entity in the model browser and select 'Stored Procedure Mapping', you'll get a window that lets you specify which stored procedures to use. MSDN has a walkthrough on how to do this.


Need Your Help

Advantages of a program containing several OpenCL kernels versus several programs with one kernel each?

c++ c opencl

This question derives from my desire to have an OpenCL program constructed at runtime from various kernels. So, imagine I have various kernels that I want to execute in a given context with the sam...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.