Compare Page Revisions
« Older Revision - Back to Page History - Newer Revision »
Install-Package EntityFramework
using System.Data.Entity; namespace NerdDinner.Domain { public class SiteDb : DbContext { public DbSet<Dinner> Dinners { get; set; } public DbSet<RSVP> RSVPs { get; set; } } }
web.config
<connectionStrings> <add name="SiteDb" connectionString="Data Source=.;Initial Catalog=NerdDinners;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /> </connectionStrings>
Application_Start()
Global.asax.cs
if (System.Diagnostics.Debugger.IsAttached) Database.SetInitializer<SiteDb>(new DropCreateDatabaseIfModelChanges<SiteDb>());
if (System.Diagnostics.Debugger.IsAttached) Database.SetInitializer<SiteDb>(new SiteDbInitializer());
public class SiteDbInitializer : DropCreateDatabaseIfModelChanges<SiteDb> { protected override void Seed(SiteDb context) { var dinners = new List<Dinner> { new Dinner { Title = "Sample Dinner 1", EventDate = new DateTime(2012,12,31), Address = "One Microsoft Way", Country = "USA", HostedBy = "scottgu@microsoft.com" }, new Dinner { Title = "Sample Dinner 2", EventDate = new DateTime(2013,5,31), Address = "Somewhere Else", Country = "USA", HostedBy = "scottgu@microsoft.com" } }; dinners.ForEach(d => context.Dinners.Add(d)); } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.