You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[NotMapped] Attribute causes a cast error with the MapIgnoreAnotationHandler.
Fix:
Write your Own Anotation Handler for NotMappedAttribute:
using System.ComponentModel.DataAnnotations.Schema;
using Detached.Mappers;
using Detached.Mappers.Annotations;
using Detached.Mappers.Types.Class;
namespace BOB.Backend.Common.AttributeHandlers
{
public class NotMappedAnnotationHandler : AnnotationHandler<NotMappedAttribute>
{
public override void Apply(NotMappedAttribute annotation, MapperOptions mapperOptions, ClassType typeOptions, ClassTypeMember memberOptions)
{
memberOptions.Ignore(true);
}
}
}
The text was updated successfully, but these errors were encountered:
Hi Nico,
Yup, there was a missing handler over there.. removed in 7.1.2.
I thought we agreed not to stop mapping for [NotMapped] but only for [MapIgnore].
A better workardound would be options.AnnotationHandlers.Remove(typeof(NotMappedAttribute));
Anyway, you already know how to create your own handlers, so, excellent..
The problem was, it should still map the properties with NotMapped, which are not in the database.
Now when I remove NotMapped from the AnnotationHandlers Dictornary, it wants to load and track the Ef Core, but they are not in the database = error.
Suggested solution:
For the NotMapped attribute, map the values from the DTo to the entity, but don't try to load/track them from the database.
[NotMapped] Attribute causes a cast error with the MapIgnoreAnotationHandler.
Fix:
Write your Own Anotation Handler for NotMappedAttribute:
The text was updated successfully, but these errors were encountered: