我正在使用 Cocktail、Devforce 2012 7.2.2 并且我有一个 codeFirst 模型。
当我尝试使用鸡尾酒预加载我的实体时,我的一个实体使用异常的时间仅将 7 个实体导入到我的 entityManager 的缓存中!按照下面的日志,导入它们大约需要 6 秒。
(DEBUG SL) 16:32:28.187 : MyApp.Common.PreLoadRepository`1:OnManagerCreated : PreLoadRepository<MyApp.Module.Domain.Entities.ModeTraitment>.Seed() imported 0 entites in 0.9998 ms. : ThreadId(1)
(DEBUG SL) 16:32:28.226 : MyApp.Common.PreLoadRepository`1:OnManagerCreated : PreLoadRepository<MyApp.Module.Domain.Entities.Motif>.Seed() imported 23 entites in 33.0001 ms. : ThreadId(1)
(DEBUG SL) 16:32:28.230 : MyApp.Common.PreLoadRepository`1:OnManagerCreated : PreLoadRepository<MyApp.Module.Domain.Entities.Attribut>.Seed() imported 0 entites in 1.0002 ms. : ThreadId(1)
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans MyApp.Module.Domain.tn.SL
Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans MyApp.Module.Domain.tn.SL
Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
...
Une exception de première chance de type 'System.NullReferenceException' s'est produite dans MyApp.Module.Domain.tn.SL
Une exception de première chance de type 'System.Reflection.TargetInvocationException' s'est produite dans mscorlib.dll
(MyApp DEBUG SL) 16:32:34.958 : MyApp.Common.PreLoadRepository`1:OnManagerCreated : PreLoadRepository<MyApp.Module.Domain.Entities.TypeInterv>.Seed() imported 7 entites in 6726.06 ms. : ThreadId(1)
(MyApp DEBUG SL) 16:32:34.972 : MyApp.Common.PreLoadRepository`1:OnManagerCreated : PreLoadRepository<MyApp.Module.Domain.Entities.TypeIdentity>.Seed() imported 2 entites in 10.0012 ms. : ThreadId(1)
日志中显示的所有异常都发生在此实体上的 entityManager.ImportEntities(entities, MergeStrategy.OverwriteChanges) 执行期间:TypeInterv
该实体使用 TPH。TypeInterv 继承了一个名为 RefenceBase 的基类。预加载器还加载了许多也继承了这个基类的实体(ModeTraitment,Attribut,...),没有任何问题!
实体如下所示:
[DataContract(IsReference = true)]
public class TypeInterv : ReferenceBase
{
[DataMember]
[Required]
public bool ForProf { get; set; }
[DataMember]
[Required]
[Taux]
public decimal TauxRet { get; set; }
[DataMember]
public RelatedEntityList<Tarif> Tarif { get { return null; } }
}
我试图清理实体以找出可能是什么问题。如果我删除 RelatedEntityList 我仍然会得到异常和过多的执行时间。如果我删除了这两个属性(只有一个没有修复它),我将不再得到异常并且实体在 7 毫秒内导入。
什么可能导致问题?我猜测与 postsharp 注入的代码有关吗?
注意:实体有一个基本的配置类:
public class TypeIntervConfiguration: EntityTypeConfiguration<TypeInterv>
{
public TypeIntervConfiguration()
{
Map(e =>
{
e.ToTable(Cst.Tables.TblReferenceBase);
e.Requires(Cst.Fields.Discriminant)
.HasValue(Cst.ReferenceBase.DiscriminantTypeInterv);
});
Property(p => p.ForProf)
.HasColumnName(Cst.Fields.TypeIntervForProf);
Property(p => p.TauxRet)
.HasColumnName(Cst.Fields.TypeIntervTauxRet);
}
}
属性 Taux 是一个 EF 约定(我尝试在没有属性的情况下进行测试,但它没有修复它)
public class TauxConvention: Convention
{
/// <summary>
/// Constructeur
/// </summary>
public TauxConvention()
{
this.Properties()
.Where(x => x.GetCustomAttributes(false).OfType<TauxAttribute>().Any())
.Configure(c => c.HasPrecision(18, 8));
}
}
任何想法 ?