I am developing 1 sample application which will add the news and sources related to it using Code First approach. So one news has multiple sources and one source has multiple news i.e. its many to many relationship. I have created the "news" and "source" model. For creating junction table I am not using model instead it is created using Fluent API. Below is code for that.
//modelBuilder.Entity().HasKey(sn => new { sn.SourceId, sn.NewsId });
modelBuilder.Entity()
.HasMany(n => n.news)
.WithMany(s => s.sources)
.Map(ns =>
{
ns.MapLeftKey("SourceId");
ns.MapRightKey("NewsId");
ns.ToTable("SourceNews");
});
}
Now while editing the particular news I want to remove all records of that particular news and then add newone to junction table. Can any one please help in this and how to do it wihout junction table model?
Thanks
Prasad
Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Replies
Know the answer? Post it — somebody with the same question will find it here.