Z.EntityFramework.Plus MemberInitExpression错误

时间:2018-05-18 16:46:41

标签: entity-framework entity-framework-6

我使用

收到以下错误
System.Exception: Invalid Cast. The update expression must be of type MemberInitExpression. at Z.EntityFramework.Plus.BatchUpdate.ResolveUpdateFromQueryDictValues[T](Expression`1 updateFactory)

这就是我在做的事情:

    public void Update(Expression<Func<CustomerConsentEntity, bool>> expression, CustomerConsentEntity entity)
    {
        DbContext.CustomerConsents.Where(expression).Update(x => entity);
    }

    public void Update(Expression<Func<CustomerConsentEntity, bool>> expression, CustomerConsentEntity entity)
    {
        DbContext.CustomerConsents.Where(a => a.TrackingId == Guid.Parse("4D8214D5-3D43-4A3E-9572-BCDCEA6F3BF9")).Update(x => entity);
    }

    public void Update(Expression<Func<CustomerConsentEntity, bool>> expression, CustomerConsentEntity entity)
    {
        Expression<Func<CustomerConsentEntity, CustomerConsentEntity>> updateEntity = x => entity;

        DbContext.CustomerConsents.Where(expression).Update(updateEntity);
    }

我正在使用Z.EntityFramework.Plus并且已经做了几次,但这次似乎因为一些奇怪的原因而失败了。我已经尝试了几种不同的方法,同时保持签名简单,但它们都会失败。

这有效,但不理想:

        public void Update(Expression<Func<CustomerConsentEntity, bool>> expression, Expression<Func<CustomerConsentEntity, CustomerConsentEntity>> updateExpression)
    {
        DbContext.CustomerConsents.Where(expression).Update(updateExpression);
    }

0 个答案:

没有答案