Entity Framework table Mapped to an Association with No Table - c#

I created a table in SQL that just contained 2 foreign keys, Which Linked a single Bulk upload entry to many titles. After updating my edmx model.
I noticed there is no table in the diagram.
Just an Association mapped between my title table and my bulkupload table.
There is no table in the diagram so I cannot delete the table.
I cannot add things to the table because there is no connection in the C# Code. '
Does anybody have information on why this is happening and how I can fix and add this table so its able to add entries to it?

You can leave it as an association if you'd like. To add things to you junction table you add things to your Icollection so in pseducode:
BulkEntry.Titles.add(TitleToAdd)

Related

How to get the last table in entity diagram?

I created four tables in SQL Server, namely tblEmployee, tblProject, tblRoles and tblAssign. One of the tables is tblAssign which contains only two columns, both being foreign keys, which are related as primary keys in two other tables tblEmployee and tblProject.
When I use ADO.NET Entity framework model in C# project, only the three existing tables barring tblAssign are shown in the Entity diagram, even a class file for this table has not been generated. How to create a entity for tblAssign table in the project?

EF Code First - Duplicate Table With The Same Schema

EF 6 Code First: How is it possible to have duplicate table of the same schema.
Like History table that serves as a replica for the original table. For example:
Several Important Notes to Consider:
No foreign key: I know it can be done by inheritance and some other such methods which generate foreign key to the original table. But I mean completely different duplicated table.
No Copy Past the Entity: Coping from the Employee entity to Employee_History entity is an option but in case the original entity is big, complected and has lots of inheritances, it might be really mess. Not to mention that every change to the original table should be reflected to the history table manually by copy.
DataAnnotation is preferable.

Bulk Insert DataSet with multiple related tables into SQL Server C#

I have a DataSet with multiple tables the source document is an XML file.
mydataset.ReadXML(filename);
There are multiple tables with multiple relations. I have the database in the SQL created via code - tables, columns and relations.
Now I would like to insert the data . (Yes I want everything).
EDIT: The SQL tables use Identity Columns autogenerate - because I am not sure the incoming data will never duplicate one of the parameters that I would like to assume is unique.
So what methods should I do to ensure data is input considering I have foreign key constraints , how should I iterate the the tables in the dataset to make sure I don't try to insert in tables requiring an existing id. Do I create a hard coded map (I prefer not too) , or do I walk the tables looking for a Foreign key and verify the parent table etc..
Any Ideas ? I am sure someone has done this before and has a simple answer for me.
You have a couple of options. Assuming the database is not generating the key values, this is pretty simple. Either
1) You discover the order to load the tables so that each table with a Foreign Key is loaded after the table to which it refers.
2) You turn off constraint checking in SqlBulkCopy, and then optionally check the constraints after loading.
To check the constraints after load, run a command like
alter table SomeTable with check check constraint fk_SomeTable_OtherTable
If you do have database-generated keys, this is all harder. But the best way to tackle that is to use SEQUENCE objects isntead of IDENTITY columns and run sp_sequence_get_range to fetch the new key ranges to the client and apply the keys there first.

Entity Framework 6 - Navigation Property as Table

I have a table that links two other tables together. When I import these tables into the edmx file, EF automatically creates a navigation property between the two tables and does not create a entity table for the association. Which is great and useful; however, when doing some complex joins from other various tables it would be far more effective to be able to join off of the association table to limit the number of trips to the database.
I tired a solution where I would remove a table, add the middle table, and then re-add the other table. This worked; however, when building the project I get an error:
Error 3015: Problem in mapping fragments starting at lines 6123, 6490: Foreign key constraint 'fk_Um' from table UserModules (ModuleId) to table Modules (ModuleId):: Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side.
Is there a way to add in the association table, so I can directly join on it without going through the navigation property?

SqlMetal cannot generate new foreign key associations to certain tables

My team are using SqlMetal to generate database classes from a SqlServer database. It works perfectly for all of our existing classes and foreign key associations but it's refusing to generate the code for a particular new foreign key association that we want to add. This key is from an audit table to a global event table detailing the time the audit record was created and the user it was created by. Many similar foreign key associations between other audit tables and this global "event" table exist in the system and SqlMetal generates code for those associations.
I've tried resolving this problem by:
Dropping and recreating the table
Removing the primary key
Creating a new identical table with a different name
Removing all other fields from the table
Dumping the indexes
Performing a fresh database build
Renaming the foreign key
None of the above seem to resolve the problem. However, SqlMetal does correctly generate code for foreign key associations from this table to some (but not all) other tables in the system. The association between these two tables would only generate when I altered the original create table script to include the foreign key association rather than running it (or a new equivalent table) in later. Unfortunately, we need to be able to deploy this change as a script to our existing production database so this isn't an option. I've seen a couple of articles and forum posts mentioning similar problems but none seem to give any solution or even an explanation.

Categories