Showing posts with label VS 2013. Show all posts
Showing posts with label VS 2013. Show all posts

Saturday, 1 March 2014

Nice Entity Framework trick


There is a cool trick for deleting a item from a database table using the Entity Framework.

Usually you would delete an item like this:

public bool DeleteOrder(int id)
{
 Order order = contextDb.find(id);
contextDb.Remove(order);
contextDb.SaveChanges();
}

However if you want some improvement, on performance, You could re-write the above code
like this:

public bool DeleteOrder(int id)
{
 Order orderToNuke = new Order {ID:id};
contextDb.Entry(orderToNuke).State.Deleted;
contextDb.SaveChanges();
}

Entity Framework is smart to know that that order marked with the  Stated.Deleted it needs to be removed from the database.


Thursday, 14 November 2013

Entity Framework Template not available on VS 2013

Few weeks ago I installed VS 2013 in my laptop. After installing it , without any issue, I ended up having three version of Visual Studio: Visual Studio 2010, Visual Studio 2012 and Visual Studio 2013.

Over the following weeks I opened and built VS 2010 projects with VS 2013 without any problem. This week I started developing the data model of an ASP NET MVC 5 Web Application. My plan was to used the latest and greatest version of Entity Framework, EF 6.0.

To my surprise I couldn't find the template for Entity Framework on my Visual Studio 2013:





  As I didn't perform a custom installation of VS 2013 I knew that there wasn't nothing wrong with the installation process.

After fiddling around a bit with VS 2012 and VS 2013 I noticed that my installation of VS 2012 didn't have  Entity Framework 6.0 installed. So I installed Entity Framework 6.0 for Visual Studio 2012 which you can find by following this link.

Once Entity Framework 6.0 was installed on VS 2012 I run the 'repair' installation option of VS 2013 and voilĂ  the Entity Framework template was back on VS 2013