简体   繁体   English

实体框架添加记录到连接表

[英]entity framework adding record to join table

Given 3 database tables: Businesses, Markets, BusinessesMarkets 给出3个数据库表:企业,市场,企业市场

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? 如何在EntityFramework中添加连接表说话?

For example, the user wants to create a new business called ABC Co and add it to the Southern region market. 例如,用户想要创建一个名为ABC Co的新业务,并将其添加到南部地区市场。

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! EF将为您处理联接表!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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