0

I have a database table with project tasks. Each task is based on a task template, which is stored in the same table. Tasks inherit properties/fields from their associated task template record unless otherwise specified. I've created a self-referencing association in the datamodel for this table - TaskTemplateId points to the template's Id.

I am having tons of problems. I am getting a ChangeConflicException on updates even when I don't change any data in the table.

Am I going about this the right way, theoretically? Has anyone faced these two issues before?

Column name X appears more than once in the result column list.

Here is an example property:

    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; }
    }

Some notes:

  • I have set UpdateCheck to never on all the non-PK columns for this table.

EDIT: So, here is the update statement that LINQ is sending to the server:

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''

Is that not strange? Where 0 = 1? Below the code is fetching the project tasks from the server; it fires this code four times after that update statement.

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

The update statement is being fired by a LinqDataSource within a UserControl. Everything happens in markup, save for the custom properties, an example of which is at the top.

As always, thank you for your help.

Mark Williams
  • 583
  • 7
  • 18
  • Please post the code where the error is occurring as well as the SQL that is being sent to SQL Server (using SQL Profiler). Let's peek under the hood. – usr Jan 02 '13 at 22:28
  • 1
    Possible answer to your question: [Linq Update Query generates Where 0 = 1?](http://stackoverflow.com/questions/2275442/linq-update-query-generates-where-0-1) – ErikHeemskerk Feb 01 '13 at 10:27

0 Answers0