Skip to content

Use case: Explicit database table name

Christian Del Bianco edited this page May 3, 2018 · 2 revisions

In case our model has a different name from table and we cannot use Code First Data Annotations, we can manually specify table name:

    string ConnectionString = "data source=.;initial catalog=myDB;integrated security=True";

    string tableName = "Clients";
    string schemaName = "dbo";

    using(var tableDependency = new SqlTableDependency<Customers>(
        ConnectionString, 
        schemaName: schemaName, 
        tableName: tableName))
    {
        tableDependency.OnChanged += TableDependency_Changed;
        tableDependency.Start();

        Console.WriteLine("Waiting for receiving notifications...");
        Console.WriteLine("Press a key to stop");
        Console.ReadKey();
    }

This setting override Code First Data Annotations.