简体   繁体   中英

entity framework adding record to join table

Given 3 database tables: Businesses, Markets, BusinessesMarkets

I want to add a new business and I want the business to be in a particular market. How do I add to the join table in EntityFramework speak?

For example, the user wants to create a new business called ABC Co and add it to the Southern region market.

This is making some assumptions about your domain model:

var southernRegion = db.Markets().Find(the_id);
var abcCo = new Business();

southernRegion.Businesses.Add(abcCo);

db.SaveChanges();

EF will handle the join table for you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM