I am working on some CRUD methods for a web app. I am using Entity Framework with SQL Server 2008. In particular, I have two tables that are linked using a cross reference table. It's in the following format:
- Table
Tbl_PlanPlanIdPlanNmActive
- Table
Tbl_PersonPersonIdPersonNmPersonData
- Xref table
Xref_PersonPlanPersonIdPersonNm
Now, when I am creating a new plan I have been trying to link the two together. I'm not sure how. I know it has something to do with referencing the relationship or creating it.
The tables are set up correctly, because I can pull the data just fine once it's created (i.e. my sample entries in SQL Server) but creating the reference is where I am stumped. I tried the following:
using (Entities context = new Entities())
{
// TblPlan plan has already been instantiated
plan.TblPersons.Add(person);
context.AddToTblPlans(plan);
context.SaveChanges();
But obviously, the .Add() isn't what I'm looking for....help?