Programming EF with Code First (二) - Configuration for relationships

 

public class Destination
{
public int DestinationId { getset; }
public string Name { getset; }
public string Country { getset; }
public string Description { getset; }
public byte[] Photo { getset; }
public List<Lodging> Lodgings { getset; }
}

 

public class Lodging
{
public int LodgingId { getset; }
public string Name { getset; }
public string Owner { getset; }
public bool IsResort { getset; }
public decimal MilesFromNearestAirport { getset; }
public Destination Destination { getset; }
}

 

Specifying an optional one-to-many relationship

modelBuilder.Entity<Destination>()
.HasMany(d => d.Lodgings)
.WithOptional(l => l.Destination);

 

 

 

posted @ 2012-09-07 16:00  Master HaKu  阅读(229)  评论(0)    收藏  举报