Tuesday 24 May 2016

What are lazy/deferred loading and eager loading?



Lazy/Deferred Loading: In case of lazy loading, related objects (child objects) are not loaded automatically with its parent object until they are requested. By default LINQ supports lazy loading.

DataContext context = new DataContext();
var query = context.Department.Take(3); // Lazy loading
foreach (var Dept in query)
{
  Console.WriteLine(Dept.Name);
  foreach (var Emp in Dept.Employee)
  {
    Console.WriteLine(Emp.EmpID);
  }
}



DataContext context = new DataContext();
var query = context.Department.Include("Employee").Take(3); // Eager loading
foreach (var Dept in query)
{
  Console.WriteLine(Dept.Name);
  foreach (var Emp in Dept.Employee)
  {
   Console.WriteLine(Emp.EmpID);
  }
}

Friday 13 May 2016

A brief history of Asp.Net MVC framework

Release history


Date Version
10 December 2007 ASP.NET MVC 
13 March 2009 ASP.NET MVC 1.0
16 December 2009 ASP.NET MVC 2
4 February 2010 ASP.NET MVC 2 RC 
10 March 2010 ASP.NET MVC 2
6 October 2010 ASP.NET MVC 3 Beta
9 November 2010 ASP.NET MVC 3 RC
10 December 2010 ASP.NET MVC 3 RC 2
13 January 2011 ASP.NET MVC 3
20 September 2011 ASP.NET MVC 4 Developer Preview
15 February 2012 ASP.NET MVC 4 Beta
31 May 2012 ASP.NET MVC 4 RC
15 August 2012 ASP.NET MVC 4
30 May 2013 ASP.NET MVC 4 4.0.30506.0
26 June 2013 ASP.NET MVC 5 Preview
23 August 2013 ASP.NET MVC 5 RC 1
17 October 2013 ASP.NET MVC 5
17 January 2014 ASP.NET MVC 5.1
10 February 2014 ASP.NET MVC 5.1.1
4 April 2014 ASP.NET MVC 5.1.2
22 June 2014 ASP.NET MVC 5.1.3
1 July 2014 ASP.NET MVC 5.2.0
28 August 2014 ASP.NET MVC 5.2.2
9 February 2015 ASP.NET MVC 5.2.3
7 November 2015 ASP.NET MVC 6.0.0-beta1
18 November 2015 ASP.NET MVC 6.0.0-rc1


Difference between NULLIF and ISNULL

NULLIF:

NULLIF( expression , expression)

It returns a null value if both the expression is equal. NULLIF returns the first expression if both the expression is not equal.

 ISNULL:

ISNULL ( expression , replacement)

Replaces NULL with the specified replacement value. It returns the value of expression if it is not null.

Monday 9 May 2016

Call SSRS Report from MVC

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ShowReport();
        }

        private void ShowReport()
        {
            try
            {
                string printFormat = string.Empty;
                string userId = string.Empty;
                string invoiceDate = string.Empty;

                byte[] returnValue = null;
                string deviceinfo = "";
                string mimeType = "";
                string encoding = "";
                string[] streams = null;
                Microsoft.Reporting.WebForms.Warning[] warnings = null;

                if (Request.QueryString["format"] != null)
                {
                    printFormat = Request.QueryString["format"];
                }

                if (Request.QueryString["userId"] != null)
                {
                    userId = Request.QueryString["userId"];
                }

                if (Request.QueryString["invoiceDate"] != null)
                {
                    invoiceDate = Request.QueryString["invoiceDate"];
                }

                //report url 
                string urlReportServer = WebConfigurationManager.AppSettings["UrlReportServer"];

                // ProcessingMode will be Either Remote or Local 
                rptViewer.ProcessingMode = ProcessingMode.Remote;

                //Set the ReportServer Url 
                rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer);

                // setting report path 
                //Passing the Report Path with report name no need to add report extension  
                rptViewer.ServerReport.ReportPath = "/TestReports/ReportName";

                List<ReportParameter> reportParams = new List<ReportParameter>();
                reportParams.Add(new ReportParameter("UserId", userId));
                reportParams.Add(new ReportParameter("InvoiceDate", invoiceDate));

                rptViewer.ServerReport.SetParameters(reportParams);

                rptViewer.ServerReport.Refresh();

                if (printFormat == "Xls")
                {
                    //output as XLS
                    string format = "Excel";
                    string extension = "xls";
                    returnValue = rptViewer.ServerReport.Render(format, deviceinfo, out mimeType, out encoding, out extension, out streams, out warnings);
                    Response.Buffer = true;
                    Response.Clear();
                    Response.ContentType = "application/ms-excel";
                    string fileName = "TestFileName" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xls");
                    Response.BinaryWrite(returnValue);
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    //output as PDF
                    string format = "PDF";
                    string extension = "pdf";

                    returnValue = rptViewer.ServerReport.Render(format, deviceinfo, out mimeType, out encoding, out extension, out streams, out warnings);
                    Response.Buffer = true;
                    Response.Clear();

                    Response.ContentType = mimeType;
                    string fileName = "TestFileName" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".pdf");

                    Response.BinaryWrite(returnValue);
                    Response.Flush();
                    Response.End();
                }

            }
            catch (Exception)
            {
                throw;
            }
        }       
   

Default versions of C#

Default versions of C#

By default following are corresponding version of C# compilers for Visual Studio:
  1. Visual Studio 2015: C# 6.0
  2. Visual Studio 2013: C# 5.0
  3. Visual Studio 2012: C# 5.0
  4. Visual Studio 2010: C# 4.0
  5. Visual Studio 2008: C# 3.0
  6. Visual Studio 2005: C# 2.0
  7. Visual Studio.NET 2003: C# 1.2
  8. Visual Studio.NET 2002: C# 1.0