Skip to content

Entity Framework ConnectionKeyAttribute [Mapping]

Victor Tomaili edited this page May 3, 2021 · 1 revision

[namespace: Serenity.Data] - [assembly: Serenity.Data]

The ConnectionKey attribute sets the name of the connection to be used for I/O operations on the entity to which it is associated.

In this example the Product entity is associated with the Northwind connection key, that in the Web.config file is a DB connection string.

[ConnectionKey("Northwind")]
public sealed class ProductRow : Row, IIdRow, INameRow
{

In Web.config file:

<connectionStrings>
    <add name="Default" connectionString="Data Source=(LocalDb)\MSSQLLocalDB; Initial Catalog=SereneTest_Default_v1; Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="Northwind" connectionString="Data Source=(LocalDb)\MSSQLLocalDB; Initial Catalog=SereneTest_Northwind_v1; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Clone this wiki locally