I am writing a log parser for the asp.net mvc2 web application. I use the Entity structure as a model, and logging is done as using my manual mechanism along with the CDC function SqlServer2008.
When you insert or edit a row in the database, the action is logged. However, there is a slight lag between the changes that occur in the actual table and the logging of these changes. I need to display details from CDC tables when a user clicks on some of them. Due to the previously mentioned lag, I cannot compare the equivalence of the two DateTime values. I want to resolve a 2000 millisecond lag. The easiest way I know is to use Ticks or TimeOfDay and compare the absolute values of their values subtracted, but the damned Linq-To-Entities do not allow these two properties.
Here's a simple function that I come across ...
public static List<dbo_Object_CT> GetLogDetails (Int32 objectID, DateTime? actionDateAndTime)
{
ObjectEntities oe = new ObjectEntities();
var mylogdetails = (from objectLog in oe.dbo_Object_CT
join ltm in oe.lsn_time_mapping on objectLog.C___start_lsn equals ltm.start_lsn
where (objectLog.Id == objectID)
&& ((actionDateAndTime == null) ? true : (Math.Abs(actionDateAndTime.Value.Ticks - ltm.tran_begin_time.Value.Ticks) < 2000))
select objectLog).ToList();
return mylogdetails;
}
I know that I can manually make a "where" clause, but that would be big, ugly and slow. Anyone have the best deals?