Entity Data Model - Adding a Keyless Table

Visual studio gives me a trace of errors that I got stuck in. I am trying to add an existing table in a database to my data model. I understand that a table must have a key, but it is not, and I cannot fix it; this is not my redevelopment database.

When I first try to add a table, I get this error:

The table / view of 'BT8_GC.dbo.SAVED_QUERY_CATEGORY' makes the primary key undefined and no valid primary key can be displayed. This table / view is excluded. to use the entity, you will need to review your schema, add the correct one and uncomment it.

Ok, ok, I will determine the keys for it and uncomment it. Here is the block that I uncommented after I manually determined the keys (I also had to add nullable = false):

<EntityType Name="SAVED_QUERY_CATEGORY"> <Key> <PropertyRef Name="SQC_CAT_ID"/> <PropertyRef Name="SQC_USER_ID"/> </Key> <Property Name="SQC_CAT_ID" Type="int" Nullable="false" /> <Property Name="SQC_USER_ID" Type="int" Nullable="false" /> <Property Name="SQC_CAT_DSCR" Type="varchar" MaxLength="50" /> <Property Name="SQC_SEQ_NO" Type="int" /> </EntityType> 

No, now the designer will not open. Go back to the file and Intellisense shows this error:

Error 11002: Object type "SAVED_QUERY_CATEGORY" does not have an entity.

Ok ... Uncommenting created a new error. After adding a set of objects:

 <EntitySet Name="SAVED_QUERY_CATEGORY" EntityType="IssueModel.Store.SAVED_QUERY_CATEGORY" store:Type="Tables" Schema="dbo" /> 

Hooray! The designer is opening! Not yet, because while it is displayed in the Tables / Views folder of the store, in the model it does not have the Entity type. I can not name it from my code. I have no errors to work with, so I tried to create a mapping of a set of objects, but this leads to the error "does not exist in metadata in space".

So what I tried. How to get this poorly designed table in my data model?

+4
source share
1 answer

When changing the XML, you added only the database table information. Now you need to open the toolbar and add the object to your model in the designer. Configure the object for properties as needed. Then open the display data and map the new object to the table.

Btw. once you change the XML description of the database manually, you can no longer use the update from the database - the VS constructor will always delete your changes and you will have to repeat them again.

+2
source

All Articles