No relationships when generating Entities from Advantage database - entity-framework

I am trying to add tables from an existing Advantage Database (recently upgraded from v8 to v10) to a .NET project via the Entity Framework. However, no matter what I do, the relationships between the tables are not being imported from the database. Obviously, I can just recreate them in Visual Studio, but I'd prefer to keep the data structure primarily in the database.
This link describes the problem, but the solution (permissions issues) doesn't work for me. We're using the IGNORERIGHTS security mode in connections, and user permissions are not enabled on the database.
Based on this chapter, I've made sure that the tables in question are ADT tables, and have Primary keys which are non-nullable. I've also verified that the RI constraints exist and show up in Advantage's visual designer.
Despite all that, when I "Update Model from Database" in the EDMX and select the tables which have a reference between them, no reference is created.
Is there anything else I can try? Some step I'm missing? A setting that needs to change?

I ended up deleting the EDMX for entirely unrelated reasons, and when I recreated it, relationships worked just fine. It's quite possible that Mark's suggestion was the answer, but for new ones only. I didn't do any extensive testing to try and confirm that, though.

Related

keeping database in sync ef core

I have read multiple posts about this but do not have a clear answer yet.
We are transitioning to EF Core 2.0 company-wide, one project at a time.
The challenge is this:
A new project starts and a database is created using code first, migrations etc.
another programmer needs to create a project targeting the same database.
This programmer can use Scaffold-DbContext and generate current models.
However, a new column is needed and this second programmer adds it.
Now...how do we best update the other projects?
Is there something that checks and syncs or shows what is out of sync between your model and a database? Meaning check the database for changes...not the model.
We don't mind buying a tool if that is the best solution.
The solution we have been using, very successfully is the Database project in Visual Studio.
Using that each developer has the project in their solution, changes are made against it locally.
Then we can do a "Schema Compare" inside of VS.
We have been using this successfully for 4 of us the past three weeks extensively with almost no issues.
This has even worked for keeping versions and changes to our stored procedures current.
It works well with VSTS also.
Here are some of the posts I read that helped me understand it:
https://www.sqlchick.com/entries/2016/1/10/why-you-should-use-a-ssdt-database-project-for-your-data-warehouse
https://weblogs.asp.net/gunnarpeipman/using-visual-studio-database-projects-in-real-life
..and this forum had a lot of relevant questions/answers:
https://social.msdn.microsoft.com/Forums/sqlserver/en-us/home?forum=ssdt

How to manage Entity Framework model first schema updates?

I'm using Entity Framework 5 model first. Say I've deployed the application and I'd like to upgrade an EF entity with new columns, basically adding columns to the table.
What is the best way to upgrade the existing database without losing data? For example I have a User table that I add two new columns to. If I try to script a schema change the tables will need to be dropped in order to add the new columns. Is there a way to update the tables without needing to recreate them? Thanks!
This may be a late answer but I have had the same problem and could just find one solution, there is an application that can update the model-first generated databases without losing the data.
It can directly open the model file and update the database tables.
It also installs some extensions on Visual Studio that I have not personally used but may be usable.
The name is Entity Developer and there are some editions of the application listed here:
Entity Developer Editions
The free edition is usable only for 10 entities or less that may not suit your needs but the Professional edition is usable for 30 day as a trial that may help you do the job. The only solution I could find on the net was this one.
Hope it helps you with the problem.

EF with only a subset of existing tables

I got an existing database with many tables which are accessed using stored procedures only (no O/RM). I'd like to create new tables in this database using Entity Framework and the Code First approach.
Do all the tables in my existing database need to be modelized in my Entity Framework classes? Will I be able to hand-code only the new classes I need in my DbContext? Other tables really need to stay untouched and away from O/RM for the moment.
Note: I'm going to be using the latest EF5.
As for now the Power Tools only allow you to reverse engineer all tables and views in the DB, which can be a problem if you have a big DB, with hundreds of objects, you do not want to reverse engineer.
However, I found an easy workaround for that:
Create a new technical user for the reverse engineering. To this user you only grant permission to the tables and views, that you want to be reverse engineered.
Have fun!
You are under no obligation to map any given table with EF. If you already have a database, you may want to consider reverse-engineering your database with the EF Power Tools available from Microsoft. I did this recently with a MySQL database that I had for testing purposes and it worked quite well!
If you are new to EF an advantage is that the PowerTools write a ton of code for you, which will help you get a grasp on the syntax of Code First. You will need to modify the output but it is a great start. I really believe that this approach will give you the least headache.
The EF PowerTools can be found here: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/

entity framework crash after updating database

I am current running EF 4.3.1 which was recently upgraded from 4.1, using a database first model. I also have my model and objects spread across different assemblies.
As I'm developing however, I'm finding the entity framework almost impossible to live with, because despite having the option "update model from database", seldom can I do so without causing the designer to fire up errors.
If I add an index to a table, create a fk relationship, there's a good chance that the designer will show a 'object null reference exception' when I try do do anything with the database afterwards. To make it even harder, the error message is exactly that vague, not pointing to what it actually could be.
I have asked a question elsewhere and the response I got back was to recreate the edmx. Surely not when I have 60 to 80 entities?
I can't believe that I'm the only one with the issue, and i can't believe any developer could live with the situation, but I can't find information anywhere as to what the issue is - if in fact its not 'by design'.
Can anyone help?
The reason for the crash is due to the de-sync'd relationship between the edmx and the dbcontext.
When changes, or even refresh is applied to the edmx you MUST run the custom tool update before exiting the project. Failure to do this will result in a corrupt edmx., which I have yet not managed to fix without restoring/recreating it.
Whilst this is in your hands most of the time, obviously there are occasions when this is outside of your control and should be something managed by the framework rather than depend on your ability to remember and the will of god. Hopefully longer term this will be included in the framework.

Entity Framework 4.0 'Code First' approach

I've been working Entity Framework trying to get better with it. I'm liking what I'm seeing thus far but now have a question. With this new 'Code First' approach (from the CTP 4 download) we can now use EF from a code first approach, but I'm trying to find out if one can use an existing EDMX file with this approach.
I have a project I'm working on which has an EDMX file and I notice the ModelBuilder has a RegisterEdmx method but am not finding a lot out there on whether this will allow to use an existing EDMX file with my code first approach.
Also, I know with this new CTP things like RecreateDatabaseIfModelChanges are avilable but these options drop the database and recreate it, wont this cause all your data to be lost if you ever change your models? Is there something I'm missing here?
I can't speak to using previously generated EDMX files but there is support to use Code First with existing databases. As for the automatic Recreate, yes, this will kill all your data. This is meant only in rapid development where the persistence of data doesn't matter (and, in fact, is likely unwanted as you discover issues with business logic and want a clean start with your updates.)
This is meant only as a quick way to develop. As of (when Scott Guthrie blogged about the CTP - jump to section 5) there are no data migration features available. Your options are to manually update the database to match your model, delete the database and let it be recreated or set the automatic recreate option. Only the first option is non-destructive to your data.