Skip to main content

Posts

Showing posts from February, 2022

Entity Framework 6.0 Logging and database Operations Interception

  Entity Framework 6.0 Logging and database Operations Interception Introduction Entity Framework 6.0 introduced a new feature called "Logging SQL". While working with Entity Framework, it sends commands or an equivalent SQL query to the database to do a CRUD operation and this command can be intercepted by application code of Entity Framework. How to enable the SQL logging The Database Log property of DbContext can be set to a delegate of any method that accepts a string as the parameter. Using this method, all SQL generated by the current context will be logged. Syntax:             public DbContextEntities () : base ( "name=EntitiesConnections" )         {             Database.Log = delegate for method which accepts string as parameter;         }   Example: For instance, if ...

TimeSpan in C#

  TimeSpan in C# The struct TimeSpan in C# represents a time interval that is difference between two times measured in number of days, hours, minutes, and seconds. The TimeSpan is used to compare two C# DateTime objects to find the difference between two dates.   Creating TimeSpan   TimeSpan struct has the following overloaded forms:   The following code snippet crates a TimeSpan from days, hours, and minutes. The common method of creating a TimeSpan is finding the difference between two DateTime objects, The following code snippet is example of getting the interval between two DateTime objects. TimeSpan Properties   C# TimeSpan class properties are Days, Hours, Minutes, Seconds, Milliseconds, and Ticks that returns days, hours, minutes, seconds, and milliseconds in a TimeSpan object. The TotalDays, TotalHours, TotalMinutes, TotalSeconds, and TotalMilliseconds properies return the totals of them on an object.   The following code snippet...