dotnet / ef6

This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.

Home Page:https://docs.microsoft.com/ef/ef6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EF6.0,IIS线程池自动回收之后,程序运行报Mapping与Entity类型不匹配

peteringz opened this issue · comments

1、在OnModelCreating(DbModelBuilder modelBuilder)方法中用如下方式初始化mapping信息
configurationInstance = Activator.CreateInstance(type);
modelBuilder.Configurations.Add(configurationInstance);
2、实体类mapping类定义方式
public class BaseEntityMapping : EntityTypeConfiguration
where T : class , new()
{
public BaseEntityMapping()
{
Init();
}
public virtual void Init()
{
}
}

public class PurchaseEntity
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int PurchaseId { get; set; }
}

public class PurchaseMapping : BaseEntityMapping<PurchaseEntity>
{
    public override void Init()
    {
        ToTable("Purchase");
    }
}

3、IIS线程池回收瞬间,刚好遇到WebAPI在运行,报如下类似错误
类型为“XXXMapping”的表达式不能用于方法“System.Data.Entity.ModelConfiguration.Configuration.ConfigurationRegistrar AddYYYContentEntity”的类型为“System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1[YYYContentEntity]”的参数

在 System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)\r\n
在 System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection1& arguments)\r\n 在 System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable1 arguments)\r\n
在 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateCall(EXPRCALL pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.VisitCALL(EXPRCALL pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Dispatch(EXPR pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Visit(EXPR pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateLambda(EXPRCALL pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.VisitCALL(EXPRCALL pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Dispatch(EXPR pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Visit(EXPR pExpr)\r\n
在 Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.Rewrite(TypeManager typeManager, EXPR pExpr, IEnumerable1 listOfParameters)\r\n 在 Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateExpressionTreeFromResult(IEnumerable1 parameters, ArgumentObject[] arguments, Scope pScope, EXPR pResult)\r\n
在 Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(DynamicMetaObjectBinder payload, IEnumerable1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)\r\n 在 Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder payload, IEnumerable1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)\r\n
在 Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, IEnumerable1 args, IEnumerable1 arginfos, DynamicMetaObject onBindingError)\r\n
在 Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)\r\n
在 System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)\r\n
在 System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)\r\n
在 System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection1 parameters, LabelTarget returnLabel)\r\n 在 System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite1 site, Object[] args)\r\n
在 System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)\r\n
在 CallSite.Target(Closure , CallSite , ConfigurationRegistrar , Object )\r\n
在 FR.Framework.ORM.MySqlProvider.MySqlDbContext.OnModelCreating(DbModelBuilder modelBuilder)\r\n
在 System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()\r\n
在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)\r\n
在 System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input)\r\n 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n 在 System.Data.Entity.Internal.InternalContext.Initialize()\r\n 在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n 在 System.Data.Entity.Internal.Linq.InternalSet1.Initialize()\r\n
在 System.Data.Entity.Internal.Linq.InternalSet1.AsNoTracking()\r\n 在 System.Data.Entity.Infrastructure.DbQuery1.AsNoTracking()\r\n
在 System.Data.Entity.QueryableExtensions.AsNoTracking[T](IQueryable`1 source)\r\n

大神们,知道这样的问题原因吗

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.