Saturday, November 7, 2020

Sql Query titbits


Generate Dates and hour between Date Range


 DECLARE 
  @start DateTime = getdate() -1, 
  @end   DateTime = getdate();

;
WITH Dates_CTE
     AS (SELECT @start AS Dates
         UNION ALL
         SELECT Dateadd(hh, 1, Dates)
         FROM   Dates_CTE
         WHERE  Dates < @end)
SELECT DAY(dates),DATEPART(hour,Dates)
FROM   Dates_CTE
OPTION (MAXRECURSION 0) 



Got better queries? .. Add in comment .. Thanks




Wednesday, July 8, 2020

ef core tips



 Debug code-first Entity Framework migration codes
 Place this piece of code right above the migration you want to debug:
  if (!System.Diagnostics.Debugger.IsAttached)
            System.Diagnostics.Debugger.Launch();
More details / Ref  : https://stackoverflow.com/a/52700520/193061

Thursday, July 2, 2020

Powershell TitBits




Replace all file names in a folder

Get-ChildItem -Filter “*ModelMap*” -Recurse | Rename-Item -NewName {$_.name -replace ‘ModelMap’ ,’ModelMapping’ }

Thursday, June 4, 2020

Java To C# mapping





   Java          C#

   Map      Dictionary
   Set      HashSet
   Pair      KeyValuePair 
   .map              .Select       
   .collect          .ToList()
   .stream           .AsEnumerable 
   LinkedHashSet     <Need custom impl >
   flatMap()         SelectMany
   format()      String.format()
   zip( .Zip(
   joining() String.Join(
   InstStream(1,100)  Enumerable.Range(1, 100)
   Function    Func 
   .apply(           .Invoke(
   .isEmpty()   .Any()
   .size()   .Count
   .filter(           .Where(
   BiFunction    Func
   

Wednesday, August 9, 2017

using Linq methods with caution - E.g FirstorDefault()


Don't use FirstorDefault() unless you are sure its valid/ verified in the business scenario. else you are going to introduce bugs in the code.


Devops links

  Build Versioning in Azure DevOps Pipelines