Created
April 16, 2015 03:30
-
-
Save dataneek/27e0496862c545c0535b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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