Data Context Attributes

This topic describes the data context attributes.

SchemaNameAttribute

The optional SchemaNameAttribute is used to define a common schema name that will be used for all stored procedures called by the data context extension methods. It should be applied to the data context class. When a stored procedure name defined in an attribute already contains a schema name, it is returned as is. If it does not and the data context has this attribute applied to it, the schema name from it is added to the stored procedure name. If not, the stored procedure name is returned as is and will use the default schema.

C#
[SchemaName("Demo")]
public sealed class DemoDatabaseDataContext : DbContext
{
    ... Data context definition ...
}

ParameterNamePrefixAttribute

The optional ParameterNamePrefixAttribute is used to define a common stored procedure parameter name prefix that will be used for all stored procedures called by the data context extension methods. It should be applied to the data context class. As an example, if set to "param" and an entity property name is AccountKey, the stored procedure parameter name will be set to @paramAccountKey. If not defined on a data context the parameter will be named after the property (@AccountKey in the preceding example).

C#
[ParameterNamePrefix("param")]
public sealed class DemoDatabaseDataContext : DbContext
{
    ... Data context definition ...
}

See Also

Other Resources