Модель пользователя:
public class User
{
[Key]
public int Id { get; set; }
public string Email { get; set; }
public string FirstName{ get; set; }
public string LastName { get; set; }
public string Password { get; set; }
public int CreatedAt { get; set; }
public virtual ICollection<Video> Videos { get; set; }
}
Модель видео:
public class Video
{
[Key]
public int Id { get; set; }
public int UserID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string File { get; set; }
public string Hash { get; set; }
public int CreatedAt { get; set; }
public int Views { get; set; }
public virtual User User { get; set; }
}
При попытке обратиться к виртуальному полю:
@foreach (Video item in Model)
{
<a href="">@item.User.FirstName</a>
}
Результат:
An exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.dll but was not handled in user code
Additional information: An error occurred while executing the command definition. See the inner exception for details.