Tuesday, 28 October 2014

Error with Entity Framework 6 after importing Stored Procedures & Functions

I have recently started using Entity Framework 6 for my VS2012 project in 4.5 framework. I was confronted with an error after importing Stored Procedures & Functions, which I did much later after importing the tables.

cannot convert from 'System.Data.Objects.ObjectParameter' to 'System.Data.Entity.Core.Objects.ObjectParameter'

The issue may have arisen because I had used EF5 in my previous project. The solution that I figured out is quite simple. We need to replace

using System.Data.Objects;
using System.Data.Entity.Core.Objects;

Thursday, 23 October 2014

I just added the Ajax control toolkit to my VS2012 project and then run the project. Got the following error.

'MsAjaxBundle' is not a valid script name. The name must end in '.js'

The name it is referring to is available in the Master page, though it doesn’t make clear as to what the error is.
How to solve it? There are a few changes to be made in the Master page.

  1. <asp:ScriptManager runat="server"> must be changed to <ajaxToolkit:ToolkitScriptManager runat="server">
  2.   The Assembly="System.Web" reference must be removed from all the ScriptReferences
  3.   MsAjaxBundle reference must be removed

Once these 3 changes are made, your application will run trouble free.

Tuesday, 14 October 2014

Getting Table Column names in Linq to Entity

We can get the list of column names of a table through SQL query using the following query:

where TABLE_NAME = 'TableName'

To get the same result while using LINQ to Entity Framework, we need to use Reflection.

using (var context = new DatabaseContext())
    var queryString = typeof(TableName).GetProperties().Select(a => a.Name).ToList();