代码优先上下文条件

时间:2017-06-10 14:01:22

标签: entity-framework ef-code-first code-first

 public class Article
{
    public List<Category> _ArticleCategory;

    public Article()
    {
        _ArticleCategory = new List<Category>();
    }

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ArticleID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Content { get; set; }
    public int Viewed { get; set; }
    public DateTime LastUpdatedDate { get; set; }
    public bool IsDeleted { get; set; }

    public virtual List<Category> Categories { get; set; }
    public virtual List<Tag> Tags { get; set; }
    public virtual List<Comment> Comments { get; set; }


}

// I want to take Articles which has more than 1 Category var result = _context.Articles.Where(a => a.Categories.Count > 1).ToList();

有我的文章类和我的代码来采取文章。我从_Context或其他地方没有问题。它给了我所有文章。 我该如何为此制定条件? 谢谢你们..

1 个答案:

答案 0 :(得分:0)

Thanx大家.. 我解决了这个问题..

public virtual List<Category> Categories { get; set; }
public virtual List<Tag> Tags { get; set; }
public virtual List<Comment> Comments { get; set; }

// this.Configuration.LazyLoadingEnabled = false; 当ı想要使用虚拟列表选项时,我应该打开这个属性。又来了。快乐编码:)