Created
April 27, 2012 23:26
-
-
Save AymericG/2514265 to your computer and use it in GitHub Desktop.
Migrating from LinqToSql to Code First Entity Framework
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
//before | |
var weeklyReview = Db.WeeklyReviews | |
.Include(x => x.WeeklyGoals) | |
.SingleOrDefault(x => x.WorkspaceId == workspace.WorkspaceId && x.WeekDate == weekStart.WeeklyReviewDay(workspace.StartOfWeek)); | |
// after | |
var weeklyReviewDay = weekStart.WeeklyReviewDay(workspace.StartOfWeek); | |
var weeklyReview = Db.WeeklyReviews | |
.Include(x => x.WeeklyGoals) | |
.SingleOrDefault(x => x.WorkspaceId == workspace.WorkspaceId && x.WeekDate == weeklyReviewDay); |
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
// before | |
public IEnumerable<Feedback> All() | |
{ | |
using (var db = new WeekPlan.Models.WeekPlanDataContext()) | |
{ | |
var o = new System.Data.Linq.DataLoadOptions(); | |
o.LoadWith<Feedback>(x => x.User); | |
db.LoadOptions = o; | |
return db.Feedbacks.OrderByDescending(x=>x.Date).ToList(); | |
} | |
} | |
// after | |
// Don't forget to add | |
// using System.Data.Entity; | |
public IEnumerable<Feedback> All() | |
{ | |
using (var db = new WeekPlan.Models.WeekPlanDataContext()) | |
{ | |
return db.Feedbacks.Include(x => x.User).OrderByDescending(x => x.Date).ToList(); | |
} | |
} |
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
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); |
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.Collections.Generic; | |
namespace WeekPlan.Models | |
{ | |
public class Workspace | |
{ | |
#region generated | |
public Workspace() | |
{ | |
this.Actions = new List<Action>(); | |
this.JournalEntries = new List<JournalEntry>(); | |
this.Roles = new List<Role>(); | |
this.Users = new List<User>(); | |
this.User_Workspace = new List<User_Workspace>(); | |
this.WeeklyReviews = new List<WeeklyReview>(); | |
this.WorkspaceInvitations = new List<WorkspaceInvitation>(); | |
} | |
public long WorkspaceId { get; set; } | |
public string Name { get; set; } | |
public long UserId { get; set; } | |
public System.DateTime DateCreated { get; set; } | |
public string MissionStatement { get; set; } | |
public string Values { get; set; } | |
public string Achievements { get; set; } | |
public bool AllowAutoMove { get; set; } | |
public short StartOfWeek { get; set; } | |
public string LongerTermGoals { get; set; } | |
public virtual ICollection<Action> Actions { get; set; } | |
public virtual ICollection<JournalEntry> JournalEntries { get; set; } | |
public virtual ICollection<Role> Roles { get; set; } | |
public virtual ICollection<User> Users { get; set; } | |
public virtual User User { get; set; } | |
public virtual ICollection<User_Workspace> User_Workspace { get; set; } | |
public virtual ICollection<WeeklyReview> WeeklyReviews { get; set; } | |
public virtual ICollection<WorkspaceInvitation> WorkspaceInvitations { get; set; } | |
#endregion | |
public bool IsTeam | |
{ | |
get | |
{ | |
return User_Workspaces.Count > 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment