Thanks Halil!
Hi Halil,
The attribute [UnitOfWork] doesn't work in Unit Tests methods? Or i need to use IUnitOfWorkManager and begin a transaction explicitly?
I've made some tests and to make it run 100% without exceptions both entities can't have soft deletes. if one entity of the relation have soft deleted the exception is raised.
Halil,
I've changed the entity to no be soft delete anymore and now is working perfectly.
What have changed from version version 0.8.4.0 to the 0.9.x ?
In this new release of abp i can't keep my entities as soft delete?
Thanks
Yes, they are soft deleted.
These entities are inherited from FullAuditedEntity.
On post [http://forum.aspnetboilerplate.com/viewtopic.php?p=5826#p5826]) i've added the entities code.
Hi Halil,
I've found one more thing that could help to understand where is the problem. If i let the method HasRequired() commented everything works fine. But this was working in the version 0.8.4.0. I've another entities mapping configuration in the same situation.
public class AgenciaMap : EntityTypeConfiguration<Agencia>
{
public AgenciaMap()
{
HasKey(x => x.Id);
Property(x => x.IsActive)
.IsRequired();
//HasRequired(x => x.Banco)
// .WithMany(x => x.Agencias)
// .Map(x => x.MapKey("BancoId"))
// .WillCascadeOnDelete(false);
Property(x => x.Nome)
.HasMaxLength(50)
.IsRequired();
}
}
Here is the DbContext code, to show how i'm loading the entities type configuration
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.AddFromAssembly(Assembly.GetExecutingAssembly());
modelBuilder.Conventions.Add<TableNameConvention>();
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
}
Hi Halil,
I've downloaded the version of AspNetZero template v1.10.1.0 and have merged with my project. But the error to delete an entity still occurs.
Here are the answers:
// Generic Domain Service
public abstract class EZControlDomainServiceBase<TEntity, TPrimaryKey> : EZControlDomainServiceBase, IService<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
where TPrimaryKey : IEquatable<TPrimaryKey>
{
public IRepository<TEntity, TPrimaryKey> Repository { get; set; }
protected EZControlDomainServiceBase(IRepository<TEntity, TPrimaryKey> repository)
{
this.Repository = repository;
}
public virtual async Task Delete(TPrimaryKey id)
{
TEntity record = null;
try
{
record = await Repository.GetAsync(id);
}
catch (Exception ex)
{
throw new UserFriendlyException("Record not found.", ex.Message);
}
if (record != null)
{
await Repository.DeleteAsync(record);
}
}
}
// Generic Application Service
public abstract class EZControlAppServiceBase<TEntity, TPrimaryKey> : EZControlAppServiceBase
where TEntity : class, IEntity<TPrimaryKey>
where TPrimaryKey : IEquatable<TPrimaryKey>
{
public virtual async Task Delete<TIdInput>(IService<TEntity, TPrimaryKey> service, TIdInput input)
where TIdInput : IdInput<TPrimaryKey>
{
await service.Delete(input.Id);
}
}
// The Application Service
public class AgenciaAppService : EZControlAppServiceBase<Agencia>, IAgenciaAppService
{
private readonly IAgenciaService _service;
public AgenciaAppService(IAgenciaService service)
{
_service = service;
}
public async Task Delete(IdInput input)
{
await Delete(_service, input);
}
}
Hi Halil,
I've upgraded the abp.* packages to version 0.9.1.0. And change the entity configuration class just like in this post [https://github.com/aspnetboilerplate/module-zero/issues/198]). But now in my tests i receive an exception when trying to delete some records.
Here is the exception message: A relationship from the 'Agencia_Banco' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Agencia_Banco_Source' must also in the 'Deleted' state.
Here are the entities definitions and map settings:
public class Agencia : FullAuditedEntity, IPassivable
{
public Agencia()
{
IsActive = true;
}
public bool IsActive { get; set; }
public virtual Banco Banco { get; set; }
public string Nome { get; set; }
}
public class Banco : FullAuditedEntity, IPassivable
{
public Banco()
{
IsActive = true;
}
public bool IsActive { get; set; }
public string Nome { get; set; }
public virtual ICollection<Agencia> Agencias { get; protected set; }
}
public class AgenciaMap : EntityTypeConfiguration<Agencia>
{
public AgenciaMap()
{
HasKey(x => x.Id);
Property(x => x.IsActive)
.IsRequired();
HasRequired(x => x.Banco)
.WithMany(x => x.Agencias)
.Map(x => x.MapKey("BancoId"))
.WillCascadeOnDelete(false);
Property(x => x.Nome)
.HasMaxLength(50)
.IsRequired();
}
}
public class BancoMap : EntityTypeConfiguration<Banco>
{
public BancoMap()
{
HasKey(x => x.Id);
Property(x => x.IsActive)
.IsRequired();
Property(x => x.Nome)
.HasMaxLength(Banco.NomeMaxLength)
.IsRequired();
HasMany(x => x.Agencias);
}
}
Here are the unit tests
[Fact]
public async Task DeletingUsingApplicationService()
{
CreateFakeData();
IAgenciaAppService agenciaAppService = Resolve<IAgenciaAppService>();
await agenciaAppService.Delete(new IdInput(1));
await agenciaAppService.GetById(new IdInput(1)).ShouldThrowAsync<UserFriendlyException>();
}
[Fact]
public async Task DeletingUsingDomainService()
{
CreateFakeData();
IAgenciaService agenciaService = Resolve<IAgenciaService>();
await agenciaService.Delete(1);
await agenciaService.GetById(1).ShouldThrowAsync<UserFriendlyException>();
}
The exception only occurs when using ApplicationService. But the most curious is that internally, the application service delete method calls the domain service delete method. So my guess, is there any interceptor besides the AuditingInterceptor? I've disabled the auditing in the module pre initialize method. Any idea of what can be that? In previous version of AspNetZero, it was working perfectly.
Thanks
Thanks Halil!!
Halil,
I've followed your article in code project. I've created an interceptor and is working perfectly. But now, i would like to localize some messages. How could i implement that? I've tried to inject the ILocalizationSource through the constructor, but didn't work. I receive that message:
'Abp.Localization.Sources.Resource.ResourceFileLocalizationSource' is waiting for the following dependencies:
Thanks