score:2
Create a partial class of whatever table it is. In the partial class have the following:
public partial class MyTable{
partial void OnValidate(System.Data.Linq.ChangeAction action)
{
LastEditTime = DateTime.Now;
}
}
OnValidate is always called before doing a database.submitchanges()
score:1
The simplest answer would be to assign a default value for the field in the database, i.e. getdate(). Which will ensure the field is populated with the current time/date but only if it's blank.
Linq to SQL is only an access layer on top of SQL so it's fairly dumb in that respect and you'd either need to craft the Linq to SQL classes yourself or ensure that you populate the value when you create your object instance that you are adding to the DB.
If you are looking for something that updates automatically to ensure concurrency every time you update the record then take a look at the timestamp field type.
score:0
You could create a trigger in the database and assign it to the update action. I know it works, we do this all the time on our Postgres database.
I don“t know if SQL Server has triggers, but you can use a stored procedure.
Source: stackoverflow.com
Related Articles
- How to force Linq to update last edit time of a row?
- how to update the multiple rows at a time using linq to sql?
- LINQ Source Code Available
- creating Linq to sqlite dbml from DbLinq source code
- Accessing SQL Server time in code with LINQ
- source code for LINQ 101 samples
- How to update my model code using LINQ
- Linq group by count and order by last update of the group
- Convert SQL update query to c# LINQ code
- .net linq update time part of datetime for multiple records
- Check and Update only time of DateTime Value in List<Dictionary<string, object>> using linq
- c# Linq or code to extract groups from a single list of source data
- how to use update statement for updating more than two rows at a time in linq
- How to prevent multiple users to update a record at the same time using LINQ
- Linq Update taking long time to process
- Update all objects in a collection using LINQ
- Using Linq to get the last N elements of a collection?
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ order by null column where order is ascending and nulls should be last
- Linq code to select one item
- Using LINQ to Update A Property in a List of Entities
- Update records using LINQ
- How are people unit testing code that uses Linq to SQL
- LINQ aggregate and group by periods of time
- Update using LINQ to SQL
- Use linq to generate direct update without select
- LINQ to Entities how to update a record
- Drop the last item with LINQ
- update multiple elements at once LINQ
- Group by on DataTable
- How to find the opposite of .Any()
- How to select sections of differing lengths from list using LINQ only
- How do I select multiple items from a database using LINQ
- Getting List of Routes from RouteCollectionRoute
- Handling null values and missing columns in Linq-to-Xml
- Decrement all int values in Dictionary
- Best way to write lingq for loop queries
- Count how many cells are null in a row using Linq and c#
- Returning xml sub elements from attributed elements with LINQ
- How can I extract DbFunctions/SqlFunctions call into a resuable extension/method with EntityFramework 6.2?
- How to select one item in LINQ when the other is null
- must retrieve the list from the database
- How can I use LINQ with a class that has parallel arrays?
- Replace a specific sub-string at specific position using LINQ
- Finding out if an update succeeded with LINQ SQL?
- data grid does not show data in C# wpf application
- VB Linq Group Join query FAILS to order the results in descending order
- Serialize Linq Results directly to JSON
- get last in LINQ list