NickStrupat / EntityFramework.Triggers

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

can't call Updating.Original #16

Closed somjetsomjet closed 7 years ago

somjetsomjet commented 7 years ago

when call

Triggers<Order>.Updating += x =>
{
       var a = x.Original;
}

have error => Member 'OriginalValue' cannot be called for property 'Details' on entity of type 'Order' because the property is not part of the Entity Data Model.

NickStrupat commented 7 years ago

Hi somjet,

Could you post the full code which demonstrates the issue?

somjetsomjet commented 7 years ago

please see full code https://github.com/somjetsomjet/test-ef-trigger-sample

NickStrupat commented 7 years ago

I see that Details1Error is of type IEnumerable<T>, which won't be seen by Entity Framework as a mappable type. In other words, it won't work unless you use ICollection<T>.

Once you make that change, you'll see that the exception changes to one telling you that collection types are not supported by the "Original" values look-up.

The other thing I noticed is that you're using the instance constructor (public Order()) instead of the static constructor to set up your triggers. Your code will add the trigger every time you make an Order object.

somjetsomjet commented 7 years ago

I change "IEnumerable" to "virtual ICollection" and change "public Order()" to "static Order()" but can't fix error, How to use "Original"?

have error The type initializer for 'EntityFramework.TypedOriginalValues.OriginalValuesWrapper`1' threw an exception.

Could not load type 'Order_45A70B3DD01BC4D0D28B869261AAC8E5FC7C23F053AB4D5FBD5DD88D46F1906DOriginalValuesWrapper' from assembly 'Order_45A70B3DD01BC4D0D28B869261AAC8E5FC7C23F053AB4D5FBD5DD88D46F1906D__OriginalValuesWrapperAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the parent type is sealed.":"Order_45A70B3DD01BC4D0D28B869261AAC8E5FC7C23F053AB4D5FBD5DD88D46F1906DOriginalValuesWrapper

NickStrupat commented 7 years ago

Collections are not supported by .Original, but this cryptic exception is a bug and I will look into it.