Change the return type of a DataContext method (O/R Designer)

The return type of a DataContext method (created based on a stored procedure or function) differs depending on where you drop the stored procedure or function in the O/R Designer. If you drop an item directly onto an existing entity class, a DataContext method that has the return type of the entity class is created (if the schema of the data returned by the stored procedure or function matches the shape of the entity class). If you drop an item onto an empty area of the O/R Designer, a DataContext method that returns an automatically generated type is created. You can change the return type of a DataContext method after you add it to the methods pane. To inspect or change the return type of a DataContext method, select it and click the Return Type property in the Properties window.

Note

You cannot revert DataContext methods that have a return type set to an entity class to return the auto-generated type by using the Properties window. To revert a DataContext method to return an auto-generated type, you must drag the original database object onto the O/R Designer again.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in this article. You might be using a different edition of Visual Studio or different environment settings. For more information, see Personalize the IDE.

To change the return type of a DataContext method from the auto-generated type to an entity class

  1. Select the DataContext method in the methods pane.

  2. Select Return Type in the Properties window and then select an available entity class in the Return Type list. If the desired entity class is not in the list, add it to or create it in the O/R Designer to add it to the list.

  3. Save the .dbml file.

To change the return type of a DataContext method from an entity class back to the auto-generated type

  1. Select the DataContext method in the Methods pane and delete it.

  2. Drag the database object from Server Explorer or Database Explorer onto an empty area of the O/R Designer.

  3. Save the .dbml file.