Files
hrynco-ef/HrynCo.DAL.Abstract/Entities/Entity.cs
Anatolii Grynchuk 15c58522ef feat: rebuild base repository hierarchy, add readme and agents
- replace EfRepository/BaseDbContext/UtcValueConverter with BaseEfRepository and BaseRepository
- add IEfRepository interface hierarchy
- consolidate IEntity into Entity.cs, remove standalone IEntity.cs
- add PagedResult
- adjust all namespaces to HrynCo.DAL.Abstract / HrynCo.DAL.EF
- add README.md with solution overview, versioning rules, class diagram
- add AGENTS.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-06 01:15:59 +03:00

68 lines
1.2 KiB
C#

namespace HrynCo.DAL.Abstract.Entities;
public interface IEntity
{
DateTimeOffset Created { get; set; }
object Id { get; set; }
DateTimeOffset? Updated { get; set; }
}
public interface IEntity<TId> : IEntity where TId : struct
{
new TId Id { get; set; }
}
[Serializable]
public class Entity<TId> : IEntity<TId> where TId : struct
{
protected Entity()
{
}
public Entity(TId id)
{
Id = id;
}
public TId Id { get; set; }
object IEntity.Id
{
get => Id;
set
{
if (value is TId typedValue)
{
Id = typedValue;
}
else
{
throw new InvalidCastException($"Cannot cast value of type {value.GetType()} to {typeof(TId)}.");
}
}
}
public DateTimeOffset Created { get; set; }
public DateTimeOffset? Updated { get; set; }
}
[Serializable]
public abstract class Entity : Entity<Guid>
{
protected Entity()
{
Id = Guid.NewGuid();
}
protected Entity(Guid id)
: base(id)
{
}
}
[Serializable]
public abstract class NamedEntity : Entity
{
public required string Name { get; set; }
}