Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save entity when extend a nullable extra property #5476

Closed
seventh88 opened this issue Sep 18, 2020 · 2 comments · Fixed by #5451
Closed

Can't save entity when extend a nullable extra property #5476

seventh88 opened this issue Sep 18, 2020 · 2 comments · Fixed by #5451
Assignees
Labels
Milestone

Comments

@seventh88
Copy link

seventh88 commented Sep 18, 2020

When extending DateTime? or Guid? property for entity ,can not save success.
(Guid? Property)stack trace:
System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Volo.Abp.EntityFrameworkCore.AbpDbContext1.HandleExtraPropertiesOnSave(EntityEntry entry) at Volo.Abp.EntityFrameworkCore.AbpDbContext1.ApplyAbpConcepts(EntityEntry entry, EntityChangeReport changeReport)
at Volo.Abp.EntityFrameworkCore.AbpDbContext1.ApplyAbpConcepts() at Volo.Abp.EntityFrameworkCore.AbpDbContext1.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository`2.UpdateAsync(TEntity entity, Boolean autoSave, CancellationToken cancellationToken)

(DateTime? Property)stack trace:
System.InvalidCastException: Invalid cast from 'System.DateTime' to 'System.Nullable1[[System.DateTime, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) at System.DateTime.System.IConvertible.ToType(Type type, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Volo.Abp.EntityFrameworkCore.AbpDbContext1.HandleExtraPropertiesOnSave(EntityEntry entry)
at Volo.Abp.EntityFrameworkCore.AbpDbContext1.ApplyAbpConcepts(EntityEntry entry, EntityChangeReport changeReport) at Volo.Abp.EntityFrameworkCore.AbpDbContext1.ApplyAbpConcepts()
at Volo.Abp.EntityFrameworkCore.AbpDbContext1.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository2.UpdateAsync(TEntity entity, Boolean autoSave, CancellationToken cancellationToken)

Reproduce steps:
Setp1.Add extra properties to AppUser

public virtual Guid? NullableGuidProperty { get; set; }

public virtual DateTime? NullableDateTimeProperty { get; set; }

Setp2. Config in EfCoreEntityExtensionMappings file

ObjectExtensionManager.Instance .MapEfCoreProperty<IdentityUser, Guid?>("NullableGuidProperty");

ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, DateTime?>("NullableDateTimeProperty");

Setp3.Update User

var user = await UserManager.GetByIdAsync(id);
user.SetProperty("NullableDateTimeProperty", DateTime.Now);
user.SetProperty("NullableGuidProperty", GuidGenerator.Create());
await _userRepository.UpdateAsync(user, true);

@maliming maliming self-assigned this Sep 18, 2020
@maliming maliming added this to the 3.3 milestone Sep 18, 2020
@desmored
Copy link

i am having the same problem after migrating to version 3.1.2. Is there any plan to release a fix version shortly?

@maliming maliming modified the milestones: 3.3, 3.2-final Sep 21, 2020
@maliming
Copy link
Member

Closed by #5451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants