LINQ ChangeConflictException Issue / Custom Property
-
Wednesday, January 02, 2013 7:41 PM
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 03, 2013 2:40 PM
- Moved by Bob ShenMicrosoft Contingent Staff Friday, January 04, 2013 2:12 AM (From:Visual C# )
All Replies
-
Thursday, January 03, 2013 7:13 AM
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 ShenMicrosoft Contingent Staff Thursday, January 03, 2013 8:17 AM typo
-
Thursday, January 03, 2013 2:38 PM
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=536674The 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 SunModerator Friday, January 04, 2013 2:16 AM Duplicate
-
Friday, January 04, 2013 2:52 AMModerator
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 SunModerator Wednesday, January 16, 2013 9:37 AM

