title: Sql Ce & EF Usage (self coded)
body: <p>I have a Windows Program which should be deployed without writing to AppData during Installation, but i want a Sql CE Database in there.</p>
  
  <p>So i have 2 Ideas: Deploying it to Programs and then Copying on first start up, or, what i would prefer, Coding everything.</p>
  
  <p>So i found this Thread <a href="https://stackoverflow.com/questions/10435739/deploying-vs2010-database-projects-without-vsdbcmd">Deploying VS2010 Database Projects Without VSDBCMD?</a> which basically tells me its a bad idea, but i don`t think the Answerer is allknowing and i have a better Idea. I found that Piece of Code somewhere:</p>
  
  <pre><code>string connStr = "Data Source = FooDatabase.sdf; Password = SomePassword";
  
  if (File.Exists("FooDatabase.sdf"))
      File.Delete("FooDatabase.sdf");
  
  SqlCeEngine engine = new SqlCeEngine(connStr);
  engine.CreateDatabase();
  
  using (var conn = new SqlCeConnection(connStr)) {
      conn.Open();
  
      SqlCeCommand cmd = conn.CreateCommand();
      cmd.CommandText = "CREATE TABLE FooTable(col1 int, col2 ntext)";
      cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>from here: <a href="https://stackoverflow.com/questions/6196274/create-sqlce-database-programatically">Create SQLCE database programmatically</a></p>
  
  <p>what i am asking is, if this works on any PC and what i have to do code to use Entity Framework. I was thinking of something like</p>
  
  <pre><code>public class FooContext : System.Data.Entity.DbContext 
  {
      public FooContext() : base("Data Source = FooDatabase.sdf; Password = SomePassword") { }
      public DbSet&lt;FooTable&gt; FooTables { get; set; }
  }
  
  public class FooTable
  {
      public int col1 { get; set; }
      public string col2 { get; set; }
  }
  </code></pre>
  
  <p>but i just dont get it to work.</p>
  
  <p>might be that only the connectionstring is wrong, but how do i avoid using it or how does the right one look like?</p>
  
  <p>Help plz?</p>