I first created following classes and updated to database, tables are created already.
public class Region { public int RegionId { get; set; } public string RegionName { get; set; } } public class Zone { public int ZoneId { get; set; } public string ZoneName { get; set; } } after i needed to insert foreign key into table Zone:
public class Zone { public int ZoneId { get; set; } public string ZoneName { get; set; } public virtual Region Region { get; set; } } tried: add-migration zone, and update-database.. it is not updating database. And Add-Migration is creating class with empty properties Up() & Down(). Also tried to add [ForeignKey("RegionId")] with no success. What I am doing wrong ?
EDIT: this is last version which is working:
public class Region { public int RegionId { get; set; } public string RegionName { get; set; } } public class Zone { public int ZoneId { get; set; } public string ZoneName { get; set; } public int RegionId { get; set; } public virtual Region Region { get; set; } } Also I had two Contexts, and found solution here (Answer of Brice) - EF 4.3 Auto-Migrations with multiple DbContexts in one database