Export (0) Print
Expand All

How to: 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 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.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings.

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/Database Explorer onto an empty area of the O/R Designer.

  3. Save the .dbml file.

Show:
© 2014 Microsoft