There is a DateTime field in a table and a mapped property in LinqToSQL data class. The task is to add a boolean IsWorkingTime runtime (not mapped to any column directly but calculated on read) property which will say whether the DateTime is a working hour (the date part is neither a weekend nor a holiday and the time part is between 9am and 5pm). The property should be available for LINQ queries but not affecting the database background.
How to achieve that? I use Visual Studio data classes designer to draw the model first and generate the database then.
As for adding the property, you can utilize an additional partial class definition to add it to the model. Such as
And then your extension
Where you will run into trouble is the part about wishing to use the property in Linq. If you want to use it for constructing a query going to the database, you may be out of luck. The provider will not be able to translate the property and its logic to the appropriate SQL. However, if you can get by with post-DB filtering/projecting/etc., you can use the property once the data has been returned.