keyur

keyur

  • NA
  • 363
  • 0

Entity Framework problem

Feb 9 2015 1:31 AM

Hello

Below is my model

public class Room
{
public int Id { get; set; }

public string Name { get; set; }


public virtual Floor Floor { get; set; }

public int AcUnitId { get; set; }
public virtual AcUnit AcUnit { get; set; }
}

public class AcUnit
{

public int Id { get; set; }
[Required]
public string Name { get; set; }
public int RoomId { get; set; }

public virtual Room Room { get; set; }
}

Now when i try to assign object

room.AcUnit = room1.Acunit;

I got error "A primary key property that is a part of referential integrity constraint cannot be changed when the dependent object is Unchanged unless it is being set to the association's principal object. The principal object must be tracked and not marked for deletion"

Can anybody help to resolve this?


Answers (6)