Sunday, April 26, 2015
SqlClient.SqlFunctions.DateDiff in LINQ LINQ Examples SqlClient.SqlFunctions.DateDiff
In some situation, we have to filter or delete or get records whose creation times comes under particular time like 1 hour or two hour. In below example I will going to demostrate how to use SqlClient.SqlFunctions.DateDiff in Entity Framework to delete some records which are older than 2 hours.
public DB DeleteOldRecords(DEMOEntities objEntities)
Result = DB.Unknown;
(from p in objEntities.tblDEMO.Where(x => System.Data.Objects.SqlClient.SqlFunctions.DateDiff("hour", x.Timestamp, DateTime.Now) >= 2) select p).ToList().ForEach(objEntities.DeleteObject);
catch (Exception ex)
So, In this tutorial, you have learn, How to make use SqlClient.SqlFunctions.DateDiff in LINQ with example.
Stay Tunned for more articles like this.
if you have some suggestion, question, request on
How to make use SqlClient.SqlFunctions.DateDiff in LINQ with example?.
Please use the comment box to express your views.
Disclaimer: The code samples and API available at www.sourcecodehub.com are available
absolutely free. You are free to use it for commercial as well as non-commercial
use at your own risk, but you cannot use it for posting on blogs or other tutorial
websites similar to www.SourceCodeHub.com without giving reference link to the original
article. All the code samples and API provided by the authors are solely their creation
and neither the author nor the site are responsible if it does not work as intended.