none
LINQ ChangeConflictException Issue / Custom Property RRS feed

  • Question

  • EDIT: I can't delete this post.  New thread in proper forum at http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/a3d1b842-6782-459a-90f3-c9e503d01c35

    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 ChangeConflictException 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 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.
    • Thank you as always for your help.

    EDIT: I can't delete this post.  New thread in proper forum at http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/a3d1b842-6782-459a-90f3-c9e503d01c35

    • Edited by markwilliamsps Thursday, January 3, 2013 2:40 PM
    • Moved by Bob Shen Friday, January 4, 2013 2:12 AM (From:Visual C# )
    Wednesday, January 2, 2013 7:41 PM

Answers

  • Hi Mark,

    As far as I know, Sometimes it also happens if you’re joining two tables that have the same column name and you’re not running a natural join. For instance:

     

    SELECT A.*, B.* FROM address A LEFT OUTER JOIN badaddress B

     

    If A and B both have a field with the same name you’ll have the same problem.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alexander Sun Wednesday, January 16, 2013 9:37 AM
    Friday, January 4, 2013 2:52 AM

All replies

  • Hi markwilliamsps,

    Are you using LINQ to SQL? If so, here is a more appropriate forum for this issue:

    LINQ to SQL

    http://social.msdn.microsoft.com/Forums/en-US/linqtosql/threads

    If I misunderstood you, please let me know.

    Thanks.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bob Shen Thursday, January 3, 2013 8:17 AM typo
    Thursday, January 3, 2013 7:13 AM
  • 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.

    • Merged by Alexander Sun Friday, January 4, 2013 2:16 AM Duplicate
    Thursday, January 3, 2013 2:38 PM
  • Hi Mark,

    As far as I know, Sometimes it also happens if you’re joining two tables that have the same column name and you’re not running a natural join. For instance:

     

    SELECT A.*, B.* FROM address A LEFT OUTER JOIN badaddress B

     

    If A and B both have a field with the same name you’ll have the same problem.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alexander Sun Wednesday, January 16, 2013 9:37 AM
    Friday, January 4, 2013 2:52 AM