Skip to content

Commit

Permalink
Added CodeCamperDbContext
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasMurray committed Sep 17, 2012
1 parent 62b5d25 commit f672c64
Show file tree
Hide file tree
Showing 16 changed files with 2,080 additions and 57 deletions.
119 changes: 70 additions & 49 deletions CodeCamper.Data/CodeCamper.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>d97f2ba4-b8c0-41b8-8c1f-70ac7e925ee0</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeCamper.Data</RootNamespace>
<AssemblyName>CodeCamper.Data</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>

<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>


<Reference Include="Microsoft.CSharp"/>

<Reference Include="System.Data"/>
<Reference Include="System.Xml"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />

<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CFB5CCDB-8F5F-4F67-8F7F-E571523ED384}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CodeCamper.Data</RootNamespace>
<AssemblyName>CodeCamper.Data</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="NLipsum.Core">
<HintPath>..\LIB\NLipsum.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CodeCamperDbContext.cs" />
<Compile Include="Configuration\AttendanceConfiguration.cs" />
<Compile Include="Configuration\SessionConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SampleData\CodeCamperDatabaseInitializer.cs" />
<Compile Include="SampleData\PeopleNames.cs" />
<Compile Include="SampleData\RandomSelector.cs" />
<Compile Include="SampleData\SampleTextGenerator.cs" />
<Compile Include="SampleData\SampleTrack.cs" />
<Compile Include="SampleData\TagsGenerator.cs" />
<Compile Include="SampleData\TheChosen.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeCamper.Model\CodeCamper.Model.csproj">
<Project>{353810b1-c8cb-4a8b-86bc-f74929a1bf57}</Project>
<Name>CodeCamper.Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
</Project>
37 changes: 37 additions & 0 deletions CodeCamper.Data/CodeCamperDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using CodeCamper.Model;
using CodeCamper.Data.SampleData;

namespace CodeCamper.Data
{
public class CodeCamperDbContext : DbContext
{
// ToDo: Move Initializer to Global.asax; don't want dependence on SampleData
static CodeCamperDbContext()
{
Database.SetInitializer(new CodeCamperDatabaseInitializer());
}

public CodeCamperDbContext()
: base(nameOrConnectionString: "CodeCamper") { }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Use singular table names
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

modelBuilder.Configurations.Add(new SessionConfiguration());
modelBuilder.Configurations.Add(new AttendanceConfiguration());
}

public DbSet<Person> Persons { get; set; }
public DbSet<Session> Sessions { get; set; }
public DbSet<Attendance> Attendance { get; set; }

// Lookup Lists
public DbSet<Room> Rooms { get; set; }
public DbSet<TimeSlot> TimeSlots { get; set; }
public DbSet<Track> Tracks { get; set; }
}
}
26 changes: 26 additions & 0 deletions CodeCamper.Data/Configuration/AttendanceConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Data.Entity.ModelConfiguration;
using CodeCamper.Model;

namespace CodeCamper.Data
{
public class AttendanceConfiguration : EntityTypeConfiguration<Attendance>
{
public AttendanceConfiguration()
{
// Attendance has a composite key: SessionId and PersonId
HasKey(a => new { a.SessionId, a.PersonId });

// Attendance has 1 Session, Sessions have many Attendance records
HasRequired(a => a.Session)
.WithMany(s => s.AttendanceList)
.HasForeignKey(a => a.SessionId)
.WillCascadeOnDelete(false);

// Attendance has 1 Person, Persons have many Attendance records
HasRequired(a => a.Person)
.WithMany(p => p.AttendanceList)
.HasForeignKey(a => a.PersonId)
.WillCascadeOnDelete(false);
}
}
}
16 changes: 16 additions & 0 deletions CodeCamper.Data/Configuration/SessionConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Data.Entity.ModelConfiguration;
using CodeCamper.Model;

namespace CodeCamper.Data
{
public class SessionConfiguration : EntityTypeConfiguration<Session>
{
public SessionConfiguration()
{
// Session has 1 Speaker, Speaker has many Session records
HasRequired(s => s.Speaker)
.WithMany(p => p.SpeakerSessions)
.HasForeignKey(s => s.SpeakerId);
}
}
}
Loading

0 comments on commit f672c64

Please sign in to comment.