title: Relationships in Entity Framework Code First
body: <p>yesterday I created database in Management Studio and now I want to create it in program using EF Code First.</p>
  
  <p>Here is link to my database: <a href="http://s11.postimg.org/6sv6cucgj/1462037_646961388683482_1557326399_n.jpg" rel="nofollow">http://s11.postimg.org/6sv6cucgj/1462037_646961388683482_1557326399_n.jpg</a></p>
  
  <p>And what I did: </p>
  
  <pre><code>public class GameModel
  {
      [Key]
      public int Id { get; set; }
  
      public string Name { get; set; }
      public DateTime CreationTime { get; set; }
      public DateTime StartTime { get; set; }
      public DateTime EndTime { get; set; }
      public string TotalTime { get; set; }
      public DateTime RouteStartTime { get; set; }
      public DateTime RouteEndTime { get; set; }
      public int MaxPlayersPerTeam { get; set; }
  
      public int CityId { get; set; }
      public int CreatorId { get; set; }
      [InverseProperty("Id")]
      [ForeignKey("CreatorId")]
      //public int TeamId { get; set; }
      //[ForeignKey("TeamId")]
  
      public virtual UserModel Creator { get; set; }
      public virtual CityModel City { get; set; }
      //public virtual TeamModel WinnerTeam { get; set; }
  
  
  }
  public class RegionModel
  {
      [Key]
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public virtual ICollection&lt;CityModel&gt; Cities { get; set; }
  }
  public class CityModel
  {
      [Key]
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public int RegionId { get; set; }
  
      public virtual RegionModel Region { get; set; }
  
      public virtual ICollection&lt;UserModel&gt; Users { get; set; }
      public virtual ICollection&lt;GameModel&gt; Games { get; set; }
  }
  public class UserModel
  {
      [Key]
      public int Id { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Login { get; set; }
      public string Password { get; set; }
      public string Email { get; set; }
      public DateTime RegistrationDate { get; set; }
      public string FacebookId { get; set; }
  
      public int CityId { get; set; }
  
      public virtual CityModel City { get; set; }
  
      public virtual IEnumerable&lt;GameModel&gt; Games { get; set; }
  }
  </code></pre>
  
  <p>For now I wanted to create 4 tables but I have some problems... I want to make CreatorId in GameModel, but it doesn't work... When i wrote UserId instead of CreatorId it was working ( without [InverseProperty("Id")] and [ForeignKey("CreatorId")]).</p>
  
  <p>This is what i get:</p>
  
  <blockquote>
    <p>The view 'The property 'Id' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type.' or its master was not found or no view engine supports the searched locations.</p>
  </blockquote>
  
  <p>edit:
  I changed it like this: </p>
  
  <pre><code>    public int CityId { get; set; }
      public int CreatorId { get; set; }
  
      [ForeignKey("CityId")]
      public virtual CityModel City { get; set; }
      [ForeignKey("CreatorId")]
      public virtual UserModel Creator { get; set; }
  </code></pre>
  
  <p>And there is another problem. </p>
  
  <blockquote>
    <p>The view 'Introducing FOREIGN KEY constraint 'FK_dbo.UserModels_dbo.CityModels_CityId' on table 'UserModels' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
    Could not create constraint. See previous errors.' or its master was not found or no view engine supports the searched locations.</p>
  </blockquote>
  
  <p>And I have no idea how to solve it.</p>