Saturday, January 18, 2014

Get Entity Framework configurations out of Web.config!

This offers up the following example of handing a connection string to Entity Framework at a DbContext child in lieu of hunting for it in Web.config.

namespace MvcProject
{   
   public class Northwind : DbContext   
   {
      public Northwind() : base("Data Source=servername;Initial Catalog=database;User
            ID=yourID;Password=yourPass;Trusted_Connection=False;") {}
   }
}

 
 

Does it work. I dunno as of yet. I have not tried it.

 
 

Addendum 1/19/2014: It works! Today I made:

using System.Data.Entity;
using FluffyNothing.Core.Objects;
namespace FluffyNothing.Infrastructure.DatabaseIntegration
{
   public class PersonContext : DbContext
   {
      public DbSet<Person> People { get; set; }
      public PersonContext() : base(@"server=.\JAESCHKE;database=FluffyNothing;
            Integrated Security=true;") {}
   }
}

No comments:

Post a Comment