Browse Source

Remove IsTransient from Entity.

pull/194/head
Halil İbrahim Kalkan 8 years ago
parent
commit
60ac2397ff
  1. 8
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs
  2. 2
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs
  3. 6
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs
  4. 2
      src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

8
src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/Entity.cs

@ -22,12 +22,6 @@ namespace Volo.Abp.Domain.Entities
/// <inheritdoc/> /// <inheritdoc/>
public virtual TPrimaryKey Id { get; set; } public virtual TPrimaryKey Id { get; set; }
/// <inheritdoc/>
public virtual bool IsTransient()
{
return EntityHelper.IsTransient(this);
}
/// <inheritdoc/> /// <inheritdoc/>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
@ -44,7 +38,7 @@ namespace Volo.Abp.Domain.Entities
//Transient objects are not considered as equal //Transient objects are not considered as equal
var other = (Entity<TPrimaryKey>)obj; var other = (Entity<TPrimaryKey>)obj;
if (IsTransient() && other.IsTransient()) if (EntityHelper.IsTransient(this) && EntityHelper.IsTransient(other))
{ {
return false; return false;
} }

2
src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/EntityHelper.cs

@ -25,7 +25,7 @@ namespace Volo.Abp.Domain.Entities
/// This method is exists to help developers who want to directly implement <see cref="IEntity{TPrimaryKey}.IsTransient"/> /// This method is exists to help developers who want to directly implement <see cref="IEntity{TPrimaryKey}.IsTransient"/>
/// but want to use default IsTransient implementation as a shortcut. /// but want to use default IsTransient implementation as a shortcut.
/// </summary> /// </summary>
public static bool IsTransient<TPrimaryKey>(IEntity<TPrimaryKey> entity) public static bool IsTransient<TPrimaryKey>(IEntity<TPrimaryKey> entity) // TODO: Completely remove IsTransient
{ {
if (EqualityComparer<TPrimaryKey>.Default.Equals(entity.Id, default)) if (EqualityComparer<TPrimaryKey>.Default.Equals(entity.Id, default))
{ {

6
src/Volo.Abp.Ddd/Volo/Abp/Domain/Entities/IEntity.cs

@ -20,11 +20,5 @@ namespace Volo.Abp.Domain.Entities
/// Unique identifier for this entity. /// Unique identifier for this entity.
/// </summary> /// </summary>
TPrimaryKey Id { get; set; } TPrimaryKey Id { get; set; }
/// <summary>
/// Checks if this entity is transient (not persisted to database and it has not an <see cref="Id"/>).
/// </summary>
/// <returns>True, if this entity is transient</returns>
bool IsTransient();
} }
} }

2
src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -42,7 +42,7 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
{ {
if (typeof(TPrimaryKey) == typeof(int) || typeof(TPrimaryKey) == typeof(long) || typeof(TPrimaryKey) == typeof(Guid)) if (typeof(TPrimaryKey) == typeof(int) || typeof(TPrimaryKey) == typeof(long) || typeof(TPrimaryKey) == typeof(Guid))
{ {
if (entity.IsTransient()) if (EntityHelper.IsTransient(entity))
{ {
entity.Id = Database.GenerateNextId<TEntity, TPrimaryKey>(); entity.Id = Database.GenerateNextId<TEntity, TPrimaryKey>();
} }

Loading…
Cancel
Save