Persistent and complex types are only one of the types that can be mapped to data returned from a stored procedure. This topic demonstrates how to create a domain method for a stored procedure that returns a scalar type.

To complete this walkthrough, you will need to create a new domain model based on the SofiaCarRental database.

Suppose, you have the following stored procedure (see the code-snippet below). It is based on the SofiaCarRental database. The stored procedure is named IsCarAvailable. It takes a single @CarId parameter and returns a Boolean.

If you have already generated a domain model, you could include the IsCarAvailable stored procedure by using the Update From Database Wizard.

Follow the same steps as in the How to: Create a Domain Method for a Stored Procedure topic. Except this time, you need to select the Scalar result type rather than a Persistent Type. The Scalar option indicates that the result set contains only a single unit of data. After you select the Scalar option, the Scalar drop-down will be enabled so that you can choose the type of the return value. Select System.Boolean from the drop-down.

In case your stored procedure returns a collection of scalar values, then the Scalar option will no longer work for you. In this scenario, you will need to use the Complex Type option. The Scalar option will generate a method that returns a single scalar value.

If you do not know the schema of the result returned by a stored procedure, you could use the Retrieve Result Shape button to display the result schema.

The function internally uses the OpenAccessContext.ExecuteScalar method to execute the stored procedure and return the first column of the first row in the result set. All other columns and rows will be ignored. For more information, please refer to How the Generated Methods Retrieve the Data.