Answer the question
In order to leave comments, you need to log in
How to work with dependent tables in EF?
There are 2 models
public class News
{
public int NewsID { get; set; }
public string NewsArticle { get; set; }
public virtual User User { get; set; }
public int UserId { get; set; }
}
public class User
{
public int Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public virtual ICollection<News> News { get; set; }
}
@foreach (AuthorizationNew.Models.News News in Model.News)
{
News.NewsArticle
Автор @News.User.Email
}
Answer the question
In order to leave comments, you need to log in
Gives an error
There is an open DataReader assigned to this Command that needs to be closed first.
How to fix it? And what is its meaning?
@AlexP11223 I found the error description in English, I'm interested in something else, why doesn't lazyloading always work?
Here, for example, I have two other models
public class Section
{
public int Id { get; set; }
public string SectionName { get; set; }
public int SectionIndex { get; set; }
public virtual ICollection<Theme> Theme { get; set; }
}
public class Theme
{
public int ThemeId { get; set; }
[Display(Name = "Название темы")]
public string ThemeName { get; set; }
public virtual Section Section { get; set; }
public int SectionId { get; set; }
}
@foreach (AuthorizationNew.Models.Section sc in Model)
{
sc.SectionName
@foreach (AuthorizationNew.Models.Theme th in sc.Theme.OrderByDescending(m => m.ThemeDate).Take(3).ToList())
{
th.ThemeName
}
}
@AlexP11223 Um, just added ToList() to the pass and it worked
@foreach (AuthorizationNew.Models.News News in Model.News.ToList())
{
News.NewsArticle
Автор @News.User.Email
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question