使用查找表查询多对多关系并返回所有符合条件的关系 [英] using a look up table to query a many to many relationship and return all that meet the criteria

查看:133
本文介绍了使用查找表查询多对多关系并返回所有符合条件的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表格如下:

Film具有一个filmID.

Film_actor_lookup具有FilmIDActorID.

电影Actor具有ActorID.

Film_actor_lookup表用于解决电影和演员之间的多对多关系

The Film_actor_lookup table is used to solve the many to many relationship of films and actors

我知道这段代码不太正确,不确定在哪里使用它.

I know this code is not quite right, not sure where to go with it.

public IEnumerable<Film> getAllFilms(Actor ActorName)
    {
         return(FilmEntity.Films.Where(A => A.Actors.Equals(ActorName)));
    }

此代码是否在执行我需要的操作并返回演员所在的所有电影?

Is this code doing what I need it to and return all films that the Actor is in?

推荐答案

return(Films.Where(f => f.Actors.Any(act=>act.Name == ActorName)));

您可以查找具有与该名称匹配的演员的Film.您应该能够直接针对Films进行查询.

You can look for a Film which has an actor matching the name. You should be able to query directly against Films.

您也可以按Actor

Actors.Where(act=>act.Name == ActorName).SelectMany(act=>act.Films).Distinct()

这篇关于使用查找表查询多对多关系并返回所有符合条件的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆