Thursday, March 16, 2017

DbFunctions class of Entity Framework.

Playing with date time in both dotnet and sql server (t-sql) is always challenging and painful for me. Sometimes I forget that, entity framework cannot translate expressions into sql if I convert type using Convert class. like, Convert.ToDateTime(). If I do so then entity framework throws error like:
     "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. "

To rescue from  this, Microsoft introduces DbFunctions class from EF6 version. Prior of EF6 it was EntityFunctions. There are lot of built-in functions related to datetime type has been implemented there. Check them out.

Saturday, January 28, 2017

Right Way for Editing EDMX File of Entity Framework (EF)

As an object relation mapper, Entity Framework enables user(in this case, developer) to work with relational data in object oriented manner. It helps user to do operations like insert, update, delete, search - in database without writing sql like string and getting help of intelligence of code editor like visual studio.

Updating Entity Framework from database could be hassle if user do not know where to do what. As for example, to update a stored procedure follow the following steps -

1. Open edmx file.
2. Right click and select Model Browser

Delete stored procedure
3. from Complex Type (if any)
4. from Function Imports
5. from Stored Procedure / Functions

Then save, then update from database.

If the Stored Procedure is complex type, that means, it is returning some rows (like table) then follow these steps - 

1. Write these two lines at the beginning - 

2. Use temporary table to store data and finally return that table.
    IF OBJECT_ID('tempdb..##PGM_MonthlySalaryStatement') IS NOT NULL
        DROP TABLE ##PGM_MonthlySalaryStatement

     INSERT INTO ##PGM_MonthlySalaryStatement

    SELECT * FROM ##PGM_MonthlySalaryStatement

Thats it. 

Happy coding

Thursday, June 23, 2016

Channel 9 usefull tutorials

SQL Server DB:-



TFS and Git:-

Software Testing:-



Thursday, February 18, 2016

EF error - Type '{your_entity_name}' already defines a member called '.ctor' with the same parameter types

Couple of days ago I have decided to set custom database connection string to my entity framework data model in one of my project. Then I have created a partial class with the same name of my entity and modify connection string name of base parameter. like example below -

public partial class DBPointOfSalesEntities
  public DBPointOfSalesEntities()
           : base(my.GetEntityConnectionString)

and deleted default constructor from [model].cs file.

But the problem is, whenever I update my model, it generates default constructor with default base parameter value. And occurs error for ambiguous constructor name as I have created above.

Then after googling, I found a nice solution - there is a [model].tt file which is called T4 template. Entity model is generating its automatic code based on this template. There is a specific code snippet which is responsible for generating default constructor after updating model from database each time. following is that code snippet. I have just deleted those lines and my problem fixed.
public <#=code.Escape(container)#>()
      : base("name=<#=container.Name#>")
if (!loader.IsLazyLoadingEnabled(container))
      this.Configuration.LazyLoadingEnabled = false;
foreach (var entitySet in container.BaseEntitySets.OfType())
  // Note: the DbSet members are defined below such that the getter and

  // setter always have the same accessibility as the DbSet definition
  if (Accessibility.ForReadOnlyProperty(entitySet) != "public")

Happy coding...

Wednesday, January 13, 2016

Using "Crystal Report" with "Visual Studio 2010"

First shocking news is Crystal Report tool is not included by default with Visual Studio 2010. To come back from this shock, download crystal report tool from following link

After install don't forget to restart your computer. Because this is WINDOWS. Then after creating your first report if you get the following exception -
Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies.

Than open App.Config file. Then find the attribute useLegacyV2RuntimeActivationPolicy and change the value to "true"

Happy Coding..........