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);
技术改变世界
原文地址:https://www.cnblogs.com/davidgu/p/2675198.html