We have a few applications that use the same Linq 2 SQL DataContext. One of those Apps wil do massive inserts (it's a convertor from an old system). Is it possible to change the UpdateCheck of the TimeStamp column of each table at runtime ? Only for this one app we'd like to set it to Never, all the other apps should have Always.
views:
479answers:
4AFAIK you can not change it (at least with simple means) at runtime, because it is auto-generated as attribute in the properties of the domain classes. E.g.
[Column(Name="ITM_CREATE_DATE", Storage="_ITM_CREATE_DATE", DbType="DateTime NOT NULL", UpdateCheck=UpdateCheck.Never)]
public System.DateTime CreationDate
A possible workaround (that I have never tried, so I don't know if it works) is to copy the <DataContext>.designer.cs
code in your single project, make the changes in the copy and use it without the designer.
More Info about what I'm trying to do :
I see this behaviour in the SQL Server profiler :
exec sp_executesql N'INSERT INTO [dbo].Test VALUES (@p0, @p1)
SELECT [t0].[timestamp] FROM [dbo].[Test] AS [t0] WHERE [t0].[ID] = @p2',N'@p0 uniqueidentifier,@p1 varchar(24),@p2 uniqueidentifier',@p0='EF0F12B9-825E-48A2-943A-B43E94BB00AA',@p1='tadaaa 20081106 08:41:01',@p2='EF0F12B9-825E-48A2-943A-B43E94BB00AA'
I'd like to prevent the SELECT part since this application only does INSERTS, I have a feeling that when inserting 100 000+ records, suppressing the SELECT [to].[timestamp] part might gain me a lot of performance ...
There's are several properties of the [Column] attribute that fire off that SELECT after the INSERT:
- AutoSync, which is Never by default, and is overridden by ISDBGenerated and ISDBVersion
- ISDBGenerated, which generates the behaviour you're describing.
- IsVersion, which means the field will be auto-updated every time you update/insert a record, and LINQ will also fetch the actual value after updating/inserting, resulting in the behaviour you describe.
I'm not sure whether this applied to your particular situation, but is it possible to remove these attributes from the field that's troubling you, and setting it manually, instead of letting the DB set it by itself? (or at least, don't tell LINQ the DB will set it automatically, and LINQ won't SELECT after INSERT).
This doesn't solve the actual question of fixing it for only one of the 2 projects. I'm also not sure whether LINQ stuff is done at runtime through reflection, or at compile time. If the magic is done at runtime, you may be able to remove the attribute with reflection and add it back, maybe, I don't really know.
Disclaimer: All that I said is theoretical, I haven't tested all this stuff, and haven't had enough experience with LINQ.
Just my 2 cents.