Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Entity Framework support ApplicationIntent=ReadOnly in SQLClient connection string

Does Entity Framework support ApplicationIntent=ReadOnly in SQLClient connection string? It is in reference to Read-Only access on an Availability Replica feature of AlwaysOn Availability Groups (SQL Server 2012).

like image 301
amit_g Avatar asked Mar 27 '26 05:03

amit_g


1 Answers

The only way I've found so far would involve creating the context using the connection string directly, instead of using a connection string name. This way you could append the ApplicationIntent.

string connectionString = string.Format("{0}; ApplicationIntent=READONLY", ConfigurationManager.ConnectionStrings["AppContext"].ConnectionString);

using (AppContext context = new AppContext(connectionString))
{
    var q = from row in context.table
            select row.id;
}
like image 169
Leonardo Nascimento Avatar answered Mar 30 '26 08:03

Leonardo Nascimento



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!