Entity Framework Generate from Database Generates Empty EDMX [duplicate] - entity-framework

This question already has an answer here:
AdventureWorks can't create ado.net entity data model
(1 answer)
Closed 8 years ago.
I've tried following some simple tutorials to get started with Entity Framework using the AdventureWorks databse. I'ved tried this several times and I get the same results.
Create a Class Library
Add an ADO.NET Entity Data Model
Choose Generate from Database
Create a connection to the AdventureWorks DB
Choose all the Tables and Views
Results: Generates a Blank EDMX that tells me to drag items from the Model Browser.
When I look at the Model Browser, there is nothing there to drag to the EDMX.
Any ideas what I can try?
Using SQLServer 2012 Express
Visual Studio 2012 Express (.NET 4.5)

I was having the same issue.
My table was lacking a primary key.
Adding one did the trick for me : the table appeared in the .edmx

Related

Entity Framework 6 code first existing database not generating Entity classes

Using Visual Studio 2015 with SQL Server 2012. I've been happily using code first existing database to generate my data layer with no problems, until last week. For some inexplicable reason VS will not generate the Entity classes from my database tables (any solution, any projects, different databases and SQL instances).
The DbContext inheriting model class is generated containing the public DbSet properties for each table, also the OnModelCreating method which contains an entity<>.Property assignment for each field in each table.
Basically VS can talk to the database, read the schema, map and create everything except the entity classes. I am working on Win Server 2008R2 and applied a number of updates prior to the issue. I have since removed the updates, uninstalled then reinstalled VS but to no avail. Searching the web does not highlight anyone else who has encountered this. Can anyone help please? (VS 2013 is working fine).

Entity Data Model Wizard not creating tables in EDMX file

I'm trying the database first approach by creating an ADO.NET Entity Data Model using the wizard with the Adventureworks2012 DB.
Testing DB connection works, and the connection string is added to the App.Config.
I'm selecting all the tables except the ones marked as (dbo) AWBuildVersion, DatabaseLog, and ErrorLog.
When the wizard finishes the .edmx file is blank, and if I view the file in XML view the EntityContainer is empty.
After the model is created it returns this error in the output window:
Unable to generate the model because of the following exception: 'The
table AdventureWorks2012.Production.Document is referenced by a
relationship, but cannot be found.
I'm using VS 2010 & .NET Framework 4.0
It seems that Entity Framework does not know how to deal with data types like hierarchyid set on a table field. I removed the Production.Document table for the list of entities to include solving my problem.
Note also that this reference below was for Adventureworks 2008R2 with EF version 1.0 from Code Plex SQL Sever, and I am using Adventureworks 2012 from the same CodePlex site using EF version 4.4.
Reference: http://msftdbprodsamples.codeplex.com/wikipage?title=AW2008Details
Note: EF 1.0 Compatibility Issues
The Entity Framework team would like us to let you know that AdventureWorks2008 is a little bit ahead of the curve in terms of the Katmai features it uses. Some datatypes in AdventureWorks2008 (such as hierarchyid and geometry) are not supported in the entity framework. The workaround is to exclude tables like Production.Document from your model if possible since there is currently no support for the hierarchyid datatype in Entity Framework 1.0. Unfortunately the Entity Framework tooling which updates your model from the database will pull in tables like Production.Document even if they were specifically excluded when the model was created, so use of that feature on AdventureWorks2008R2 is not supported at this time. We look forward to a follow-on release of Entity Framework which has full SQL Server 2008 type support.
Last edited May 25, 2010 at 2:22 PM by bonniefe, version 17
There is a way to get around this IF you're trying to learn from this example and not doing anything meaningful. I deleted the foreign keys to the offending table and removed it and was able to succesfully get
Uncheck [Allow Nulls] Check-boxes (in the table design) for all the foreign keys of the not created Tables (Tables not converted to the model).
Then you can update your model to retrieve those tables by doing the following steps:-
Step 1 - Right click some where in your .EDMX file's design (i.e. Model1.EDMX [Diagram1].
Step 2 - then from the Context Menu select / Update Model from Database....
Step 3 - then select "Add"
Step 4 - then expend "Tables" Check-Boxes and select your desired tables (tables not created first time).
Step 5 - then click Finish button.
Step 6 - Save the the solution and hope everything will be Ok.
Note: I'm using Visual Studio 2013.
Good luck.

When I used TPH, all the tables recreated

I am developing an EF - MVC 3 application. I have used model first approach, so I have create model first and from that model, EF generated the DB.
I have used a tool called Nuget - Entity Generator - Database designer for generating the database. When I have designed the model first time, I have used the Generate Migration T-SQL and Deploy option of that tool.
Database generated perfectly and it's working fine...
Now I have come across a situation that I have to make a change to the model and I have to use T-SQL Via T4 (TPH) option to update the database.
So previously I used different process to update DB and now I am changing it.
When I use the T-SQL Via T4 (TPH) all the tables get deleted and new tables get created.
How to avoid this ?
I want to only update the table which I have made the changes.
Entity framework 4.3 comes with migration support. This is not available in EF 4.1.
Some links from google:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

how does the Table _MigrationHistory under the CODE FIRST in the Entity Framework create? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB
when use the entity framewrok code first mode to build database, a table '_MigrationHistory' of system table type will be created. how do I manually create table like that? the code first tutorial show us how to code first to build a new database,not on an exist database, and when I want to use the database migration function of the code first on existing database , I found I failed. and NO table named '_MigrationHistory' created. and I found a solution 'http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/' can resolve my problem, but there is a step need to copy(should be 'create' here) the table '_MigrationHistory' to the existing database which is object of system type, how do I create a table like that?
I WAS POOR IN ENGLISH, MIGHT MY EXPRESS MAKE YOU CONFUSED. HOEP NOT.
You don't need to create __MigrationHistory manually. You just need to create initial migration. The initial migration will create the table for you. This command will add initial migration called InitialMigration and ignore all entities you have in your project:
Add-Migration InitialMigration -IgnoreChanges
It means that you should run this command when your classes in the application reflect your initial database. All changes which should be handled by migrations must be done after creating the initial migration. Here is the whole tutorial.

Which type of Entity generator to use?

I am writing my first WPF and EF application. I am using SQL CE database and I have added few tables to the DB. The EF diagram is generated and now I want to generate the classes. I am new to EF and MVVM both.
When I right-click on a Table diagram, it gives option "Add Code Generation Item..". On selecting it, there are two options:
Add Entity Object Generator
Add Self-Tracking Entity Object Generator
I want to know what is the difference between the two. Which one should I use? I also want to know which one is latest and what is POCO?
A POCO is a Plain Old CLR Object... a simple class that has only properties.
http://en.wikipedia.org/wiki/Plain_Old_CLR_Object
There are 3 approaches that the Entity Framework delivers.
Model first (you create a model in visual studio and generate the database)
Database first (thats what you do, you generate a model from a existing database)
Code first (the newest one, you just write you POCOS and the entity framework generates the database)
I think it is enough to generate the diagram from database. The context and models should be available after this.
Neither of those is the POCO generator. The best way to get that is to install Entity Framework 4.1. You'll then see some new options in the list to add a code generation item.
I'm a pretty big fan of the DbContext/POCO generator added in 4.1 as the code it creates is VERY easy to work with compared to the older stuff, and it works well in a DB First setup like you're using (which is also what I use).
You can give this code generator a try:
http://salardbcodegenerator.codeplex.com/
It generates data annotations and implements INotifyPropertyChanged for CodeFirst approach.