Using Parameters with the EntityDataSource Component
This section discusses more in-depth how to pass parameters to a method of the ObjectContext/DbContext with the EntityDataSource
component. The provided examples and code snippets assume an existing Entity Data Model of the Adventure Works sample database with the following structure:
The EntityDataSource Wizard can detect parameters of the data-retrieval method, and it will ask you to provide values for them at Configure Data Source Parameters step.
The EntityDataSource
component can call a method of the ObjectContext/DbContext based on the name of the method, and additionally based on the arguments which make the signature of that method. For example, let us extend the AdventureWorksEntities
context using a partial class that defines the following method:
To call the above method specify its name to the ContextMember
property and define a data source parameter in the Parameters
collection for each method argument. The names and types of the data source parameters must match exactly the names and types of the corresponding method arguments otherwise the EntityDataSource
component will raise an exception at runtime. The following code snippet illustrates how to pass parameters to the previous method programmatically:
When declaring a data source parameter you can specify a default value for that parameter and the value will be passed automatically to the corresponding method argument. Instead of supplying the parameter value directly, you can specify an expression to be evaluated at runtime. For example, this way it is possible to link the data source parameter to an existing report parameter, as shown in the following code snippet: