Note that there are some explanatory texts on larger screens.

plurals
  1. POApplication error with SQL CE 4.0 and ASP.NET MVC 3
    primarykey
    data
    text
    <p>I have problem with rebuilding db after Model have been changed/updated. I have three table inside one db file "Posts", "Threads" and "Relations". If i run app and post new thread everything seem fine, I can see thread. If I try to add post on the thread it throws an error saying it cannot find table by name "Thread". If I check "Database Explorer" in Visual Web Developer i can only see table "Posts" which is awkward. Now I read somewhere that db is not created until first use of model (saving?).</p> <p>My models setup is:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using System.Data.Entity.Database; using System.ComponentModel.DataAnnotations; using System.Data.Entity.ModelConfiguration; namespace aspnet_forum.Models { public class Threads { public int ID { get; set; } [Required] public string Name { get; set; } [Required] public string Author { get; set; } public DateTime Date { get; set; } public string Slug { get; set; } } public class ThreadsDBContext : DbContext { public DbSet&lt;Threads&gt; Threads { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { DbDatabase.SetInitializer(new MyThreadsDBContextInitializer()); base.OnModelCreating(modelBuilder); } } public class MyThreadsDBContextInitializer : DropCreateDatabaseIfModelChanges&lt;ThreadsDBContext&gt; { protected override void Seed(ThreadsDBContext dbContext) { // seed data base.Seed(dbContext); } } } </code></pre> <p>I also used "DropCreateDatabaseAlways" resulting same error. Posts model is same as Thread with additional field "text" and Posts name where relevant.</p> <p>Relations model:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Data.Entity.Database; using System.Data.Entity.ModelConfiguration; namespace aspnet_forum.Models { public class Relations { public int ID { get; set; } [ForeignKey("Threads")] public int ThreadID { get; set; } //public virtual Threads Thread { get; set; } [ForeignKey("Posts")] public int PostID { get; set; } //public virtual Posts Post { get; set; } } public class RelationsDBContext : DbContext { public DbSet&lt;Relations&gt; Relations { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { DbDatabase.SetInitializer(new MyRelationsDBContextInitializer()); base.OnModelCreating(modelBuilder); } } public class MyRelationsDBContextInitializer : DropCreateDatabaseIfModelChanges&lt;RelationsDBContext&gt; { protected override void Seed(RelationsDBContext dbContext) { // seed data base.Seed(dbContext); } } } </code></pre> <p>My Web.Config is:</p> <pre><code>&lt;connectionStrings&gt; &lt;add name="ThreadsDBContext" connectionString="Data Source=|DataDirectory|Forum.sdf" providerName="System.Data.SqlServerCe.4.0"/&gt; &lt;add name="PostsDBContext" connectionString="Data Source=|DataDirectory|Forum.sdf" providerName="System.Data.SqlServerCe.4.0"/&gt; &lt;add name="RelationsDBContext" connectionString="Data Source=|DataDirectory|Forum.sdf" providerName="System.Data.SqlServerCe.4.0"/&gt; &lt;/connectionStrings&gt; </code></pre> <p>I tried and created all tables and relations by hand and it all works as expected I just don't know if relations will work as expected.</p> <p>Trying to establish M2M relation between Threads, Posts and Relations table.</p> <p>PS: there is "EdmMetadata" table.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload