NickStrupat / EntityFramework.Triggers

Adds events for entity inserting, inserted, updating, updated, deleting, and deleted
MIT License
373 stars 46 forks source link

TypeInitializationException on accessing Original property - already added virtual.. please help #45

Closed PowerOfGit closed 5 years ago

PowerOfGit commented 5 years ago

Hello - I know its an old issue but the answer on previos posts doesn't solve the probleme for me.. what i mean is I've already added the virtual keyword to all attributes.

Here is the example code of entity which prodeces that error.

public class ApplicationMember 
{
    static ApplicationMember()
    {
        Triggers<ApplicationMember>.Updating += entry =>
        {
            ApplicationMember V1 = entry.Entity;
            ApplicationMember V2 = entry.Original;

            if(V1.Email != V2.Email)
            {

            }
        };
    }

    public virtual Int32 ID { get; set; }

    [DataType(DataType.EmailAddress)]
    public virtual String Email { get; set; }

    [DataType(DataType.Password)]
    public virtual String Password { get; set; }

    public virtual ICollection<ApplicationMember> ApplicationMembers { get; set; }
}

If I remove public virtual ICollection<ApplicationMember> ApplicationMembers { get; set; } I'm able to access the original property but with that line its not possible and thow that exception.

System.TypeInitializationException: "Der Typeninitialisierer für "EntityFramework.TypedOriginalValues.OriginalValuesWrapper`1" hat eine Ausnahme verursacht."

Would be thanksfull for every help :)

BTW: It's a really awesome libary :)

Greetz PowerOfGit

NickStrupat commented 5 years ago

Which version of the library are you using?

PowerOfGit commented 5 years ago

I was using version 6.1.1 moving to 6.2.0 fixed that issue - thanks for that hint :)

Keep up the great work :)

Greetz PowerOfGit