0

I am working with a Windows Forms Application and have added Entity Framework 6 to the project. I have created a class where I can pass in the table name so I can use one class with many different tables. I want to use EF Code First without the wizard. How do you set the connection string for the DbContext? I know in ASP.NET MVC you can set it in the app.Config file but this is a Windows Forms Application. How do you set the connection string in order to get the data from the SQL Server?

public class TimerContext : DbContext
{
 private readonly string _tableName;
 public TimerContext(string tableName) : base("name=TimerContext")
 {
 _tableName = tableName;
 }
 protected override void OnModelCreating(DbModelBuilder modelBuilder)
 {
 modelBuilder.Entity<Timer>().ToTable(_tableName);
 base.OnModelCreating(modelBuilder);
 }
 public IEnumerable<Timer> Timers { get; set; }
}
asked Nov 20, 2014 at 2:09

1 Answer 1

1

Right click on your project, choose Add -> New Items -> Application config file.

Add you connection string in the newly created app.config file and you're done.

answered Nov 20, 2014 at 2:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.