Note that there are some explanatory texts on larger screens.

plurals
  1. POLack of a many-to-many linking table in EF 4.0 a bug or a feature?
    primarykey
    data
    text
    <p>I have a comment and a question. Entity Framework 4.0 does not show the linking table in a many-to-many relationship between two tables, such as shown in Northwind for “Order_Details”, a linking table between Orders and Products, if only two columns, both primary keys, are used in the linking table, as is often the case. So in Northwind if you use as primary keys both OrderID and ProductID in the Order_Details linking table between Orders and Products, for the many-to-many relationship, the linking table will not show up if only these two columns (primary keys) are present in Order_Details.</p> <p>Consequently, you cannot Insert or Create in a many-to-many relationship linking table, because Entity Framework 4.0 does not show the linking table Order_Details nor does Intellisense show this linking table of the many to many relationship. How is one to then do an insert or update in the linking table if EF 4 does not show the hidden linking table? Arguments such as 'you must now start thinking in OOP' do not impress me. SQL has a certain structure and OOP is just an interface for it so we can use LINQ-to-entities rather than the clumsier SQL queries, IMO.</p> <p>The trick to get around this bug was suggested for Silverlight here, <a href="http://forums.silverlight.net/t/159414.aspx/1" rel="nofollow">http://forums.silverlight.net/t/159414.aspx/1</a> , and it works for web services and any other .NET solution: simply add, in your linking table, a dummy column of any type.</p> <p>Now delete your original .edmx file, and rebuild a new one by generating it against the actual database.</p> <p>Then intellisense shows the linking table, and then you can Insert / Create and do other normal oprations.</p> <p>For example, Intellisense in EF 4.0 will now show the linking table Order_Details, and you can create or insert such as (partial fragment,omitting try/catch and any rollback options): </p> <pre><code> using (aDBEntity context = new aDBEntity()) Order_Details newOrdDetails = new Order_Details(); newOrdDetails.OrderID = //some number here newOrdDetails.ProductID = //some number here context.AddToOrder_Details(newOrdDetails); context.SaveChanges(); </code></pre> <p>Question: is this lack of showing a many-to-many linking table a bug or a feature of EF 4.0?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload