【问题标题】:Where() method and many to many relationship with the entity frameworkwhere() 方法与实体框架的多对多关系
【发布时间】:2013-08-19 21:07:29
【问题描述】:

我的数据库中有两个表,分别是视频和标签。 Video 表具有三个字段:名称、ID 和标签列表。 Tags 表有两个字段:tagName、tagID。

VideoViewModel model = new VideoViewModel
{
    Videos = repository.GetVideos
                        .Where(v => v.Name.Contains("Apple"))
};

现在假设我有多个视频,其中名称中有 Apple,但其中只有一个具有绿色,因为它是 Tags.TagName 我该如何继续?

【问题讨论】:

    标签: entity-framework


    【解决方案1】:

    假设您在dbContext 中将Videos 定义为db,试试这个

    var result = db.Videos.Where(x => x.Name.Equals("Apple"))
                          .Where(x => x.Tags.Count(y => y.tagName.Equals("Green")) == 1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      相关资源
      最近更新 更多