Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

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(); 
        }
    }

Add comment



biuquote
  • Comment
  • Preview
Loading






Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume