EF4 Slow Association Access

I am building an ASP.NET 4 web application using EF4 and I have tables like this:


Product Attribute

Product_Attribute_Map

Product_Attribute_Map is a crosstab, many of many. Thus, a product can have zero or many attributes and vice versa.

In the code, I do this:

//Attribute a = new Attribute(); // Edit:
Attribute a = (from a in context.Attributes where a.AttributeID = 1 select a).First();
a.Name = "test"; 
Product.Attributes.Add(a);

I noticed a problem that makes this very slow. EF4 will execute this SQL query on the server:

SELECT 
[Extent2].* FROM  [dbo].[Product_Attribute_Map] AS [Extent1]
INNER JOIN [dbo].[Product] AS [Extent2] ON [Extent1].[ProductID] = [Extent2].[ProductID]
WHERE [Extent1].[AttributeID] = @p1

I don’t understand why he does it. The attribute can be assigned to 10,000 products, which makes this bad request. It takes more than 5 seconds to add an attribute to the product ...

How can I prevent EF4 from choosing all attributes? And just select the attributes for this product.

thank

Edit: Only the POCO t4 template is used. The EntityObject pattern does not have this problem.

+3
1

: - LazyLoading, FixUpCollections, POCO. , fixup - prduct , , . ... POCO, , Products ( ).

+1

Source: https://habr.com/ru/post/1790560/


All Articles