Entity Data Model Designer not showing tables - visual-studio-2010

I am trying to create a Entity Data Model via an existing database,
So i follow these steps in visual studio 2010:
Add new Item->Entity Data Model
Select "Generate From Database"
Select a connection string, test the connection string and its ok
Select the tables, stored procs etc to import, no tables show up at this point, but i do check the "tables" selection - im assuming tho that it should list my tables here.
Then after these steps the Entity Data Model visual tool (ie. double click on .edmx file) shows no tables - i have tables in my database, and the username and pass im using to connect has permissions to access these tables ok.
thanks.

Open your edmx file in a text editor. If you see the tables in the file but not in the designer, try clearing out all the EntitySet nodes and EntityType nodes, save the file, then go back to Visual Studio and try the Update Model from Database again.
<edmx:StorageModels>
<Schema Namespace="myModel.Store">
<EntityContainer Name="MyModelStoreContainer">
delete-> <EntitySet Name="Table1" ... />
delete-> <EntitySet Name="Table2" ... />
</EntityContainer>
delete-> <EntityType Name="Table1">...</EntityType>
delete-> <EntityType Name="Table2">...</EntityType>
</Schema></edmx:StorageModels>

I also had a similar problem. But in my case, it was due to missing Primary Key in the selected table. So, I added a primary key, and updated the model from the Database.
After that, I could see the table, and all the columns!

i has the same problem, i solved adding in the DataConnection filter adding all the schemas, i don't now exactly wath table has missing index or primery keys, etc, but doing this i solve and show all the data.

Related

Visual Studio 2013 Dataset Designer refresh relations

I have an application with a dataset linked to an sql server database. I have updated some of the names or foreign keys and primary keys in the sql server. How do I make those changes translate to the data set. For example, I had a primary key called fk_temsempl_xxxxx. I changed it to fk_temsempl on the sql database. How do I get that change to show in the dataset designer in visual studio?
I have tried running custom tool by right clicking on the dataset and clicking run custom tool. That didnt work. I tried configuring the table adapter of one of the tables where a change occured, but the name of the relation didnt change.
You actually just right click the relation and choose Edit Relation... or double click on the line (when the mouse cursor changes from arrow to drag symbol) but I honestly wouldn't bother; you'll then have further refactoring to do in the code anywhere the relation is used, and it can be heavily used by visual designers.
You also get the problem that VS may not help you with the refactoring: in data binding scenarios most things that can be a source of data can also be a collection of multiple things that can be a valid DataSource. They then rely on a string DataMember to determine which of the collections of data in the data source should be used for the data.
For example, when a bindingsource is bound to list a DataTable, the bindingsource.DataSource property might be the DataSet object that contains the DataTable, and thebindingsource.DataMemberis a string of "YOUR_TABLE_NAME". the BindingSource might not be bound asmyBindignSource.DataSource = myDataSet.MyDataTable`. Refactoring inside strings involves a find and replace
DataRelations in a DataSet are created from foreign keys as they were discovered when the relevant table(s) were added to the dataset but it is important to note that, like DataTables and everything else, they are NOTHING to do with the database schema objects at all - they aren't permanently associated with them, the dataset entities are just set up looking something like the database objects when they (dataset entities) are first created. DataTables are created from only those columns selected, and whatever .NET datatypes closely resemble the types output by the query. For a table of:
Person
------
Name VARCHAR(50)
SSN INTEGER
Birthdate DATE
If you created the table with SELECT * FROM Person you'd get a datatable with Name (string), SSN (int), Birthdate (datetime) but if you made a new datatable in the dataset based on SELECT LEFT(Name, 1) as Initial, PADLEFT(SSN, 20) as PadSSN, DATEDIFF(day, Birthdate, NOW()) as AgeDays FROM Person then you'd get a datatable of Initial (string), PadSSN (string), AgeDays (int) - i.e. the datatable looks nothing like the db table. This concept of disconnection between dataset and db is pervasive, and really the only things that relate in any way to the database are the properties that specify which DB table/column a particular DataTable/DataColumn relates to for purposes of loading/saving data. Your Person.Name datacolumn can be renamed to Blahblah, but it will still have a .SourceColumn property that is set to "Name" - that's how the mapping between dataset and db works; dataset is predominantly completely independent of the db. Renaming a DB column would require a change to the SourceColumn property only
DataRelations don't even have this notion of linking to the parent relation in the database; there's no SourceRelation or SourceFK proeprty because there is no need to. They're set up with the same rules and a generated name all based on the rules of the FK, but then they function independently and only within the dataset. If you rename or even remove an FK from the db the dataset will carry on working in the same restricted way it always did; adding a datarow to a child table when no aprent row exists for it will throw an exception - none of it anything to do with the FK in the db, and the DataRelation can have different rules to the FK (e.g it can cascade deletes when the FK is NOACTION) or even different columns. You can have more or fewer DataRelations than the DB has FKs
Run Custom Tool is not a "contact the DB and see what changes have occurred there and replicate them into the dataset", it is a "turn the XSD that describes the dataset into a bunch of C# classes that implement strongly typed dataset/table/relation/column etc objects". Any time you change the XSD by making an edit in the visual designer and hit save, the custom tool is run. If you edit the XSD directly in a text editor you may need to run it manually to have your changes reflected in c# classes
Reconfiguring a tableadapter probably won't do anything to the relations either; its solely concerned with changing the datatable and tableadapter. If you really want to refresh the relations, delete the datatable from the set and recreate it. Be prepared for a potentially significant mop up/refactoring of code

I Changed some tables, updating EDMX model some tables are "lost"

I have an SQL database with 200 tables.
I changed the primary key on one "basic" table.
I changed ALL foreign keys referring to that table, in more than 20 tables.
I Updated the LinQ model (right-click, update model from DB) to reflect the changes in the model itself.
As a result, 3 tables disappeared from the model (they are not visible in the graphical view of the model), and I get errors: Error 3013: mapping problem from line xxxx: no mapping fot table "tablename"
Trying to update again, if I look on the details of the tables to add, I can't see the 3 tables "lost": they are in the DB, I'm sure, and SEEM to be in the model, because they aren't in the list of tables that I can add, but they aren't in the model.
What could I do in this situation?
It seems solved ... one friend suggested to open manually the edmx file with an editor (I used Notepad++), and remove any reference at the 3 tables (they were there), save, and try the update again, and the tables appeared again.

Issues while generating entities from Views

I am using an Oracle database to generate my EF entities and context.
I do not have control over schema, its all provided by client, and I strictly can't change anything over there.
I have to generate entities for various Views.
When I do this, it is adding all non-nullable columns as the keys (as I can see while opening the edmx in XML editor).
How can I specify which columns should be used as keys? Can I do anything in at EF level without changing the schema?
Ok, I found the solution. We can do this in EF. Select each column in entity, and Set "Entity Key" to "True/ False".

Entity Framework 4 doesn't recognize referential integrity in my database

Trying to test the option of replacing our internal data access layer with Entity Framework 4 in our existing web application, I have started a new project and added an ADO.NET Entity Data model, then let it generate from the existing database.
It recognizes the tables in my database but it doesn't show any relationships between these tables, they are totally separated from each other. Is there any preconditions on the database so one can use the database first method?
DBMS is SQL Server 2005, PK and FK are defined in the database.
Thank you in advance
The foreign key constraints are part of the storage model. You can use the model browser window to view the constraints. This window is probably only available with Service Pack 1 of Visual Studio.
The Entity Framework uses a memory model and a conceptual model. These are stored in a. Edmx file. It is a common XML file that can be edited using any text editor. The foreign key constraint appears in elements like
<Association Name="FK_X_Y_NNNN">; ... </Association>
In the Model Editor foreign key references are indicated by lines between the entities. At the ends of the lines the cardinality is indicated.
If you see no foreign key constraints, then the database may not define them. Check your Database please.

How do I refresh the relationships in a dataset?

I a working in VisualStudio 2005. I have a dataset with sevaral datatables in it already. I had to modify the database to add a new foreign key that I forgot about. How do I get visual studio to recognize the new relationship?
.Net does not load FK relationships into your DataSet automatically - however, you can add them yourself with a DataRelation*.
*this may not be true if you are using LINQ - if you are, I am unsure.
Right-click on the DataSet page, and select Add->Relation?
If you've defined it in your database, you can always re-drag the affected table back into the Dataset then re-enter your Queries.

Resources