GAH! Google is such phail, Bing is no better either. Been trying to find out how to use EF + SqlCe without having to specify any settings in my web.config.
Finally I found this page on unit testing that pointed be in the right direction.
And here is how to do it in code!
public class testModel
{
[Key]
[Required]
public int ID { get; set; }
[Required]
public int SomeID { get; set; }
}
public class MyClass : System.Data.Entity.DbContext
{
public MyClass() { }
public MyClass(string filename) : base(filename) { }
public DbSet TableTest { get; set; }
}
public class HomeController : Controller
{
public ActionResult Index()
{
var path = this.Context.Server.MapPath("~/bin/");
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", path, "");
Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
var tmp = new MyClass("test.sdf");
tmp.TableTest.Add(new testModel() { SomeID = 5 });
tmp.SaveChanges();
return this.View();
}
}