Tip 39 – How to set overlapping Relationships – EF 4.0 only

Scenario: In EF 4 we have FK relationships, available for the first time in .NET 4.0 Beta 2, so it is now possible to have a model something like this: public class Division {    public int DivisionID {get;set} // Primary Key    public string Name {get;set;}    public virtual List<Lawyer> Lawyers {get;set;}    public…

1

Tip 17 – How to do one step updates with AttachAsModified(..)

Background: In Tip 13 – How to Attach the easy way I showed you how to ‘establish’ the EntitySet for a particular CLR Type so you could Attach it. But in all the tips so far the same basic pattern is used: Attach the original version of the Entity Modify it SaveChanges I’ve given you…

2

Tip 11 – How to avoid Relationship Span

Background and Motivation: In my last post on EF Jargon I introduced the concept of Relationship Span. If you remember Relationship Span is basically responsible for compensating for the lack of Foreign Key properties* in your Entity. Relationship Span for an Entity, lets say StaffMember, insures that the Entity Framework knows the EntityKeys of the…

5

Tip 9 – How to delete an object without retrieving it

Problem The most common way to delete an Entity in the Entity Framework is to pull the Entity you want to delete into the context and then delete it like this: // Find a category by ID by // TRIVIA: in .NET 4.0 you can use .Single() // which will throw if there is more…

16