知道了。以下是它的工作原理,以防其他人阅读。#1 和#2 是焦点。
非常感谢@BonyT 让我走上了正确的道路......
using (JONDOEntities myEnt = new JONDOEntities())
{
// #1) Need to create WAPublicUser object first
var wap = (from w in myEnt.WAPublicUsers
where w.WAPublicUserID == 981
select w).FirstOrDefault();
var proUser = (from p in myEnt.Professionals
where p.WAPublicUser.WAPublicUserID == wap.WAPublicUserID
select p).FirstOrDefault();
// If the record does not exist in the Professional table, insert new record.
if (proUser == null)
{
JONDOModel.Professional pro = new JONDOModel.Professional()
{
ProfessionalType = "unknown",
FirstName = "unknown",
LastName = "unknown",
PhoneNumber = "unknown",
WebsiteUrl = "unknown",
TaxID = "unknown",
BusinessInfo = "unknown",
ProfessionalLogo = "unknown",
IsApproved = true,
CATaxExempt = false,
WAPublicUser = wap // #2) Plug in the WAPublicUser object here
};
myEnt.AddToProfessionals(pro);
myEnt.SaveChanges();
}