[英]Can I avoid performance problems with complex types in entity framework 6
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. 派生类中有多个
mm
实例,因此在大约10个派生类的层次结构中,总共有大约100 mm
字段。 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) ...... 生成的数据库架构是正确的,并且大致如下所示:表base1列id(guid)列名(string)列mm1_g(guid)列导出1mm1_g(guid)列派生1mm2_g(guid)列派生2mm1_g(guid)......
On startup, the first query in EF ( the one which warms things up ) takes tens of seconds. 在启动时,EF中的第一个查询(预热查询)需要数十秒钟。
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; 如果我用与之对应的单个字段替换mm复杂类型,则结果类如下所示:public abstract class base1 {public Guid id {get; set;
组; } public String name { get;
} public String name {get; set;
组; } public guid mm1 { get;
} public gui 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. mm是一种复杂类型,本身并不是一个实体,并且没有为其创建任何表,因此不涉及任何联接。
This sounds like a bug of some kind in EF6's model generation implementation where large numbers of complex type fields are involved. 这听起来像是EF6的模型生成实现中的某种错误,其中涉及大量复杂类型字段。
Does anyone have a workaround which will allow me to retain the complex type. 是否有人有变通办法,使我可以保留复杂类型。 Is this a known bug?
这是一个已知的错误?
I've recently done some Entity performance improvements on an eCommerce application. 我最近在电子商务应用程序上做了一些实体性能改进。
Somethings we learned, that might help you 我们学到的东西可能对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.