Skip to content

Use case: Explicit database table name

christiandelbianco edited this page Jun 18, 2017 · 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";

    using(var tableDependency = new SqlTableDependency<Customers>(ConnectionString, 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.

Clone this wiki locally