I am having trouble saving my entities to the database using EntityFramework. I have to tables, Player and Address. The Player table has a reference to the Address table by means of an AddressId foreign key relationship. So Player.AddressId points to Address.AddressId.
Now when calling the following code, I get an error that says: "A dependent property in a ReferentialConstraint is mapped to a storage-generated column"
public override int CreatePlayer(BizObjects.Player player)
{
var entity = new EntityFramework.Player();
entity.PlayerId = player.PlayerId;
entity.FirstName = player.FirstName;
entity.LastName = player.LastName;
entity.Gender = player.Gender;
entity.BirthDate = player.BirthDate;
entity.DisplayAge = player.DisplayAge;
entity.Level = player.Level;
entity.PlayingHand = player.PlayingHand;
entity.BackhandType = player.BackhandType;
entity.PlayingStyle = player.PlayingStyle;
entity.Description = player.Description;
entity.UserId = player.UserId;
entity.Address = new Address();
entity.Address.AddressId = player.Address.AddressId;
entity.Address.Line1 = player.Address.Line1;
entity.Address.Line2 = player.Address.Line2;
entity.Address.City = player.Address.City;
entity.Address.State = player.Address.State;
entity.Address.ZipCode = player.Address.ZipCode;
_entities.AddToPlayer(entity);
_entities.SaveChanges();
return entity.PlayerId;
}
I am new to using EF. Any pointers is greatly appreciated.