Reputation: 126
I have a complex type
[ComplexType]
public class mm
{
public Guid g { get; set; }
}
and an inheritance hierarchy
public abstract class base1
{
public Guid id { get; set; }
public String name { get; set; }
public mm mm1 { get; set; }
}
and various derived classes:
public class derived1 : base1
{
public mm derived1mm1 { get; set; }
}
The derived classes have multiple mm
instances in them, so that with a hierarchy of approximately 10 derived classes there are a total of about 100 mm
fields.
The resulting database schema is correct and looks roughly like this:
table base1
column id (guid)
column name (string)
column mm1_g ( guid)
column derived1mm1_g (guid)
column derived1mm2_g (guid)
column derived2mm1_g (guid)
......
On startup, the first query in EF ( the one which warms things up ) takes tens of seconds.
If I replace the mm complex type with individual fields corresponding to it so the resulting classes look like this: public abstract class base1 { public Guid id { get; set; } public String name { get; set; } public guid mm1 { get; set; } }
and various derived classes:
public class derived1 : base1
{
public guid derived1mm1 { get; set; }
}
, the startup time is sub one second. The only difference is that I've flattened out the complex type, which is not a good answer if the complex type has multiple fields and its own behaviour.
Just to be clear, this performance hit happens only on the very first query, and happens even if there is absolutely no data in the database.
mm is a complex type, not an entity in its own right and there are no tables created for it, so there are no joins involved or anything.
This sounds like a bug of some kind in EF6's model generation implementation where large numbers of complex type fields are involved.
Does anyone have a workaround which will allow me to retain the complex type. Is this a known bug?
Upvotes: 0
Views: 523
Reputation: 2464
I've recently done some Entity performance improvements on an eCommerce application.
Somethings we learned, that might help you
Upvotes: 1