开发者

Hibernate many-to-many delete

I 开发者_如何学编程have many-to-many relationship in NHibernate between two classes Actor and Movie.

public ActionResult removeMovieFromActor(int MovieId, int ActorId)
{
    ViewData["SectionTitle"] = "Usunięcie filmu";
    ActorsRepository ar = new ActorsRepository();

    Actor act = ar.getActor(ActorId);

    // What to do here?

    return RedirectToAction("listMovies");
}

How can I remove a Movie from act.Movies and make that persistent to the database?


Hard to tell without seeing more of your model and how your mapped your relationships. Assuming you have IList<Movie> Actor.Movies...

Movie movie = mr.GetMove(MovieId);
act.Movies.Remove(movie);
ar.Update(act);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜