Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

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;
 
with
 
using System.Data.Entity.Core.Objects;

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:

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
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();                                     
}