Skip to content

Instantly share code, notes, and snippets.

@dataneek
Created April 16, 2015 03:30
Show Gist options
  • Save dataneek/27e0496862c545c0535b to your computer and use it in GitHub Desktop.
Save dataneek/27e0496862c545c0535b to your computer and use it in GitHub Desktop.
using System;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
namespace TripIt
{
class Program
{
static void Main(string[] args)
{
using (var context = new CalendarDbContext())
{
foreach(var item in context.Periods)
{
item.ReportableFrom = DateTime.Now;
item.LastUpdated = DateTime.UtcNow;
Console.WriteLine(item.Period);
}
Console.WriteLine(context.SaveChanges());
}
}
}
//[Table("Period")]
public class CalendarPeriod
{
// [Key]
public int Period { get; set; }
public DateTime DateTo { get; set; }
public DateTime DateFrom { get; set; }
public DateTime? ReportableFrom { get; set; }
public DateTime LastUpdated { get; set; }
}
public class CalendarDbContext : DbContext
{
public CalendarDbContext()
: base("name=DefaultDbContext")
{
}
public virtual DbSet<CalendarPeriod> Periods { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CalendarPeriodEntityConfiguration());
}
}
public class CalendarPeriodEntityConfiguration : EntityTypeConfiguration<CalendarPeriod>
{
public CalendarPeriodEntityConfiguration()
{
HasKey(t => t.Period);
ToTable("Period");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment