我正在使用 Linq To Sql 保存一个包含许多子实体的实体,只是想知道是否有人遇到过这个错误:The identifier cannot be an empty string
我只是想知道是否有人遇到过它,你做了什么来解决这个问题?也许我会很幸运,您的解决方案之一会奏效。
这可能无济于事,但这是代码失败的地方
public void SaveJob(object sender, CancelEventArgs e)
{
Job = JobEditorUtilities.CreateNewJob(jobid, SettingsManager.OpsMgrSettings.Region.Trim(), _db);
try
{
var canSaveJob = CanSaveJob();
if (canSaveJob)
{
JobEditorUtilities.PrepareJobForSaving(Job);
if (newjob)
_db.JobNumbers.InsertOnSubmit(Job);
var a = _db.GetChangeSet();
_db.SubmitChanges(); // fails here
RenameJobNumberIfNecessary();
}
else
{
e.Cancel = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public static JobNumber CreateNewJob(int jobid, string region, DataAccessDataContext dc)
{
var job = new JobNumber();
job.JobID = jobid;
InitializeSubContractor(dc, job);
job.GWDRunSummaryDatas = new GWDRunSummaryData();
job.CorrectionsApplieds = new CorrectionsApplied();
job.MonitorInfos = new MonitorInfo();
InitializeGWDHeader(dc, job);
job.Rpt_Details = new Rpt_Detail();
job.RunningModes = new RunningMode();
job.SafetyIssuesTotals = new SafetyIssuesTotals();
job.SafetyIssueTotals = new SafetyIssueTotals();
switch (region)
{
case "NA":
InitializeNA_Header(dc, job);
job.NA_WRdetails = new NA_WRdetail();
InitializeNA_BillingCompany(dc, job);
job.NA_RigDetails = new NA_RigDetail();
job.NA_Holedetails = new NA_Holedetail();
job.NA_Salesmans = new NA_Salesman();
InitializeNA_WL_Company(dc, job);
break;
case "EU":
InitializeEAC_Header(dc, job);
break;
}
return job;
}
private static void InitializeNA_WL_Company(DataAccessDataContext dc, JobNumber job)
{
job.NA_WL_Companies = new NA_WL_Company();
job.NA_WL_Companies.Resource =
dc.Resources.FirstOrDefault(r => r.Refno == job.NA_WL_Companies.WL_companyid);
}
private static void InitializeGWDHeader(DataAccessDataContext dc, JobNumber job)
{
job.GWD_Header2s = new GWD_Header2();
job.GWD_Header2s.GWDDirComp2 =
dc.GWDDirComp2s.FirstOrDefault(g => g.ID == job.GWD_Header2s.MWD_Company);
}
private static void InitializeNA_BillingCompany(DataAccessDataContext dc, JobNumber job)
{
job.NA_BillingCompanies = new NA_BillingCompany();
job.NA_BillingCompanies.Resource =
dc.Resources.FirstOrDefault(r => r.Refno == job.NA_BillingCompanies.Billingcompanyid);
}
private static void InitializeSubContractor(DataAccessDataContext dc, JobNumber job)
{
job.Subcontractors = new Subcontractor();
job.Subcontractors.Resource =
dc.Resources.FirstOrDefault(r => r.Refno == job.Subcontractors.SubcontractorID);
}
private static void InitializeNA_Header(DataAccessDataContext dc, JobNumber job)
{
job.NA_Headers = new NA_Header();
job.NA_Headers.RigType1 = dc.RigTypes.FirstOrDefault(r => r.ID == job.NA_Headers.RigType);
job.NA_Headers.Well_Locn1 = dc.Well_Locns.FirstOrDefault(w => w.ID == job.NA_Headers.Well_Locn);
}
private static void InitializeEAC_Header(DataAccessDataContext dc, JobNumber job)
{
job.EAC_Headers = new EAC_Header();
}