我有一个包含项目任务的数据库表。每个任务都基于一个任务模板,该模板存储在同一个表中。除非另有说明,否则任务从其关联的任务模板记录继承属性/字段。我在这个表的datamodel中创建了一个自引用关联 - TaskTemplateId指向模板的Id。
我遇到了很多问题。即使我没有更改表中的任何数据,我也会在更新时收到ChangeConflicException。
理论上,我是否以正确的方式解决这个问题?有没有人以前遇到过这两个问题?
列名X在结果列列表中出现多次。
以下是一个示例属性:
public int NumberOfUnits
{
get
{
//If this is a task template return the actual database value
if (IsTaskTemplate)
return NumberOfUnitsPrivate;
//If there is a task template override and NumberOfUnits has a value return that
else if (IsTemplateOverride && NumberOfUnitsPrivate != 0)
return NumberOfUnitsPrivate;
//Else return the value in the task template record.
if (TaskTemplateRecord != null)
return TaskTemplateRecord.NumberOfUnitsPrivate;
return 0;
}
set { NumberOfUnitsPrivate = value; }
}
一些注意事项:
编辑: 所以,这是LINQ发送给服务器的更新语句:
exec sp_executesql N'UPDATE [dbo].[ProjectTasks]
SET [NarrativeSourceTypeId] = @p0, [BillNarrative] = @p1
WHERE 0 = 1',N'@p0 nvarchar(4000),@p1 nvarchar(4000)',@p0=N'',@p1=N''
这不奇怪吗? 0 = 1?代码下面是从服务器获取项目任务;它会在更新语句之后四次触发此代码。
exec sp_executesql N'SELECT [t0].[Id], [t0].[IsActive], [t0].[CmsMatterUno], [t0].[ProjectCategoryId], [t0].[ProjectStatusTypeId], [t0].[ProjectTemplateId], [t0].[Code], [t0].[Description], [t0].[StartDate], [t0].[FinishDate], [t0].[CreatedDate], [t0].[CreatedBy], [t0].[ModifiedDate], [t0].[ModifiedBy], [t1].[Id] AS [Id2], [t1].[IsActive] AS [IsActive2], [t1].[OrderBy], [t1].[ProjectTemplateId] AS [ProjectTemplateId2], [t1].[ProjectId], [t1].[ParentTaskId], [t1].[ProjectCategoryId] AS [ProjectCategoryId2], [t1].[IsTaskTemplate], [t1].[TaskTemplateId], [t1].[UnitTypeId] AS [UnitTypeIdPrivate], [t1].[DescriptionQualifierTypeId], [t1].[NarrativeSourceTypeId] AS [NarrativeSourceTypeIdPrivate], [t1].[CmsPhTaskUno] AS [CmsPhTaskUnoPrivate], [t1].[CmsBillTranUno], [t1].[Code] AS [Code2], [t1].[Description] AS [Description2], [t1].[IsPricingLevel], [t1].[IsCostingLevel], [t1].[NumberOfUnits] AS [NumberOfUnitsPrivate], [t1].[UnitPrice] AS [UnitPricePrivate], [t1].[StartDate] AS [StartDate2], [t1].[CompletionDate], [t1].[BillNarrative] AS [BillNarrativePrivate], [t1].[IsTemplateOverride], [t1].[BillingDate], [t1].[IsApprovalRequired], [t1].[IsTimeAssigned], [t1].[IsSummTimeOnBill], [t1].[IsAllowTime], [t1].[IsAllowBill], [t1].[IsAllowDisb], [t1].[CreatedDate] AS [CreatedDate2], [t1].[CreatedBy] AS [CreatedBy2], [t1].[ModifiedDate] AS [ModifiedDate2], [t1].[ModifiedBy] AS [ModifiedBy2], (
SELECT COUNT(*)
FROM [dbo].[ProjectTasks] AS [t2]
WHERE [t2].[ProjectId] = [t0].[Id]
) AS [value]
FROM [dbo].[Projects] AS [t0]
LEFT OUTER JOIN [dbo].[ProjectTasks] AS [t1] ON [t1].[ProjectId] = [t0].[Id]
WHERE [t0].[CmsMatterUno] = @x2
ORDER BY [t0].[Id], [t1].[Id]',N'@x1 int,@x2 int',@x1=360930,@x2=536674
更新语句由UserControl中的LinqDataSource触发。一切都发生在标记中,除了自定义属性,其中一个例子位于顶部。
一如既往,感谢您的帮助。