Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Not Generating Classes for Tables or Procedures

I'm using the Entity Framework to generate the classes and functions in C# I need to interact with the SQL server.

For reference, here's one of my tables:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Area](
    [ID] [bigint] identity (1, 1) primary key,
    [Name] [nvarchar](100) NOT NULL
    )
GO

After running the Entity Data Model Wizard (using 'EF Designer from database'), my project has the edmx file and a few new .cs files, but it seems like it's not generating everything it needs.

In my DatabaseEntities class, for example, I've got:

    public virtual DbSet<Area> Areas { get; set; }

However, there's no definition for the type 'Area' (along with three other missing types). I'm also missing the functions for stored procedures.

I've tried deleting the new files and re-running the Model Wizard, but I get the same result.

Has anyone else run into this?

SIDENOTES:

I've noticed during the last few attempts that I'm also getting an error when the wizard runs: "The Entity Framework package not installed on project". However, it's still generating the edmx and the model.context when I click past it.

I've had the same problem with both Entity Framework versions 6.0.0 and 6.1.2.

Reinstalling the framework had no effect on the problem(s).

UPDATE:

Uninstalling nuget and reinstalling the latest version allowed me to install EntityFramework via nuget without error. However, now the ADO.NET data model is missing from the Add New Item dialogue.

like image 455
Nightmare Games Avatar asked Feb 17 '15 22:02

Nightmare Games


People also ask

Does Entity Framework create tables?

Save this answer. Show activity on this post. If you're using a Code First approach then Entity Framework will build the table for you. It looks like you are not using Code First, so you will have create the table in the database.


2 Answers

Make sure the table has a key column. It will not generate the view if there is no key column in a table.

like image 155
Divakar Mayakrishnan Avatar answered Sep 21 '22 09:09

Divakar Mayakrishnan


There were several steps involved in what I did, and I have to give some credit to the people who commented below the question.

1) I uninstalled nuget package manager and reinstalled the latest version (apparently mine was not fresh). This allowed me to install EntityFramework via nugget with no errors or rollback messages.

2) I'm not sure if this helped or not, but I also reinstalled Entity Framework Tools for Visual Studio via Microsoft's website. I'm still not sure if it's necessary to have both.

3) The ADO.NET Entity Data Model template appeared to be missing from the Add New Item dialogue. After selecting "Add -> Component" instead of "Add -> New Item", it then mystically appeared under both lists.

Once that was done, I was able to run EF Designer and everything generated with no problem.

like image 44
Nightmare Games Avatar answered Sep 21 '22 09:09

Nightmare Games