我使用以下LINQ方法创建空EmploymentPLan
。之后我只是UPDATE
。出于某种原因,这对我自己很有效,但对于我的用户,他们会收到以下错误 - >
The target table 'dbo.tblEmploymentPrevocServices' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
最奇怪的是,您可以看到他们所做的以下生成的SQL实际上包含INTO子句。 WTH ???
此应用程序是一个WinForm应用程序,它连接到本地SQL 2005 Express数据库,该数据库是合并复制拓扑的一部分。这是仅通过ClickOnce安装的INTERNAL应用程序。
public static Guid InsertEmptyEmploymentPlan(int planID, string user)
{
using (var context = MatrixDataContext.Create())
{
var empPlan = new tblEmploymentQuestionnaire
{
PlanID = planID,
InsertDate = DateTime.Now,
InsertUser = user,
tblEmploymentJobDevelopmetService = new tblEmploymentJobDevelopmetService(),
tblEmploymentPrevocService = new tblEmploymentPrevocService()
};
context.tblEmploymentQuestionnaires.InsertOnSubmit(empPlan);
context.SubmitChanges();
return empPlan.EmploymentQuestionnaireID;
}
}
经过进一步审核后,我发现之前已接受的解决方案并未真正适用,因为Auto-Sync
ALREADY 设置为永远不会包含所有 ID列。< / p>
有没有其他想法?感谢
他是生成的SQL。我知道它很长但我只是不知所措。这是由上面的单个方法生成的所有内容。
DECLARE @output TABLE([EmploymentPrevocID] UniqueIdentifier)
INSERT INTO [dbo].[tblEmploymentPrevocServices]([AvgRatePay], [AvgHoursWeek], [SettingID], [PrevocGoal], [SkillsTaught], [SkillsLearned], [AnticipatedTransitionPlans], [AnticipatedEndDate], [RatioID])
OUTPUT INSERTED.[EmploymentPrevocID] INTO @output
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8)
SELECT [EmploymentPrevocID] FROM @output
-- @p0: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p1: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p2: Input Int (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p3: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p4: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p5: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p6: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p7: Input DateTime (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p8: Input Int (Size = 0; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.4926
DECLARE @output TABLE([JobDevelopmentServicesID] UniqueIdentifier)
INSERT INTO [dbo].[tblEmploymentJobDevelopmetServices]([TypeWorkDesired], [PreferredWorkHoursID], [NeedEmploymentServices], [DVRProvidingServices], [DVRCurrentReferral], [PaidCoachingHoursID], [PlanSegregatedToIntegrated], [RoleResponseJobDeveloper], [RoleResponseMember], [RoleResponseWWCTeam], [PlanDVRToWWCFund], [PlanReducePaidSupports])
OUTPUT INSERTED.[JobDevelopmentServicesID] INTO @output
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11)
SELECT [JobDevelopmentServicesID] FROM @output
-- @p0: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p2: Input Bit (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p3: Input Bit (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p4: Input Bit (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p5: Input Int (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p6: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p7: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p8: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p9: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p10: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p11: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.4926
DECLARE @output TABLE([EmploymentQuestionnaireID] UniqueIdentifier)
INSERT INTO [dbo].[tblEmploymentQuestionnaire]([PlanID], [CommunityJob], [PrevocServices], [JobDevelopmentServices], [PrevocServicesID], [JobDevelopmentServicesID], [InsertUser], [InsertDate], [UpdateUser], [UpdateDate], [TransitionedPrevocToIntegrated], [EmploymentServiceMatchPref])
OUTPUT INSERTED.[EmploymentQuestionnaireID] INTO @output
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11)
SELECT [EmploymentQuestionnaireID] FROM @output
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [37017]
-- @p1: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p2: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p3: Input Bit (Size = 0; Prec = 0; Scale = 0) [False]
-- @p4: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [a3674e69-9b78-df11-b74e-001e0bd023bc]
-- @p5: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [a4674e69-9b78-df11-b74e-001e0bd023bc]
-- @p6: Input VarChar (Size = 9; Prec = 0; Scale = 0) [pschaller]
-- @p7: Input DateTime (Size = 0; Prec = 0; Scale = 0) [6/15/2010 11:31:13 AM]
-- @p8: Input VarChar (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p9: Input DateTime (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p10: Input Bit (Size = 0; Prec = 0; Scale = 0) [Null]
-- @p11: Input Bit (Size = 0; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.4926
答案 0 :(得分:4)
嗯,这个错误看起来很清楚,而且很有道理。一些想法:
SomeName\MyTable
而不是dbo.MyTable
),你的副本没有触发器? 答案 1 :(得分:4)
您的数据库有一个触发器,它会干扰生成的sql的OUTPUT子句。
由于触发器可能不是可以删除的东西,因此您需要停止生成的sql具有OUTPUT子句。
为此,请将表格中每列的AutoSync
属性设置为Never
。这可以在LinqToSql设计器中完成。
http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.autosync(v=VS.100).aspx
这样做之后,出现了一个新问题。您的方法想要返回生成的ID,但不会自动为您提取生成的ID。您必须更改方法以查询新插入的记录。
答案 2 :(得分:2)
这适用于你吗?
http://support.microsoft.com/kb/961073
FIX:运行DML时出现错误消息 LINQ to SQL应用程序中的语句 在SQL Server 2008中:“目标表 “DML声明” 如果没有任何启用的触发器 该语句包含一个OUTPUT 没有INTO条款的条款“