Following this tutorial, I've created my DbConfiguration class:
class ImgSigDbConfig : DbConfiguration
{
public ImgSigDbConfig()
{
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
}
}
And told my DbContext to use it:
[DbConfigurationType(typeof(ImgSigDbConfig))]
class ImgSimContext : DbContext
{
Which seems to connect fine, but I have no idea where it's storing my data, and I don't like that. I would like it to save everything to a file in the App_Data folder. How can I specify that from inside my ImgSigDbConfig constructor? (Assume I know nothing about SQL server connections)
Did some more digging and came up with this:
public ImgSigDbConfig()
{
var sqlConnBuilder = new SqlConnectionStringBuilder();
sqlConnBuilder.DataSource = ".";
sqlConnBuilder.InitialCatalog = "ImgSim.ImgSimContext";
sqlConnBuilder.IntegratedSecurity = true;
sqlConnBuilder.AttachDBFilename = @"App_Data\database.mdf";
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0", sqlConnBuilder.ToString()));
}
But now it throws:
The provider did not return a ProviderManifestToken string
Per haim and gunther's suggestions I removed the superfluous connection settings:
class ImgSigDbConfig : DbConfiguration
{
public ImgSigDbConfig()
{
var sqlConnBuilder = new SqlConnectionStringBuilder();
sqlConnBuilder.IntegratedSecurity = true;
sqlConnBuilder.MultipleActiveResultSets = true;
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0", sqlConnBuilder.ToString()));
SetManifestTokenResolver(new DefaultManifestTokenResolver());
}
}
And moved them into Program.cs:
var conn = new SqlConnectionStringBuilder
{
AttachDBFilename = @"App_Data\database.mdf",
//InitialCatalog = "ImgSim.ImgSimContext",
};
using (var db = new ImgSimContext(conn.ToString()))
But even so, I get a System.Data.Entity.Core.ProviderIncompatibleException with InnerException:
The provider did not return a ProviderManifestToken string.
Even though I set a SetManifestTokenResolver -- I guess the default one doesn't work??
(localdb)\v11.0I think and you'll see the database listed