Hello Michael,
So currently, I'm using
RepoDb v1.11.0
RepoDbSqlServer v1.0.7
I'm having my domain entities deriving from this base class
[Serializable]
public abstract class Entity<T> : IEquatable<T>
{
protected Entity()
{
Id = long.MinValue;
Key = Guid.NewGuid();
Visibility = Visibilities.Visible;
DateCreation = new DateTime();
}
public long Id { get; set; }
public Guid Key { get; set; }
public bool IsNew => (Id == long.MinValue);
public Visibilities Visibility { get; set; }
public DateTime DateCreation { get; set; }
public DateTime DateModification { get; set; }
public int CreatorId { get; set; }
public int ModifierId { get; set; }
public bool Equals(Entity<T> other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != other.GetType())
{
return false;
}
bool otherIsTransient = Equals(other.Key, Guid.Empty);
bool thisIsTransient = Equals(Key, Guid.Empty);
if (otherIsTransient && thisIsTransient)
{
return ReferenceEquals(other, this);
}
return other.Key.Equals(Key);
}
public override bool Equals(object other) => other is Entity<T> entity && Equals(entity);
public bool Equals([AllowNull] T other)
{
if (other == null)
{
return false;
}
return this.Equals(other);
}
public static bool operator ==(Entity<T> a, Entity<T> b)
{
if (a is null && b is null)
{
return true;
}
if (a is null || b is null)
{
return false;
}
return a.Equals(b);
}
public static bool operator !=(Entity<T> a, Entity<T> b)
{
return !(a == b);
}
public override int GetHashCode() => (Id, Key).GetHashCode();
}
Example
[Serializable]
public sealed class Participant : Entity<Participant>
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
With my current version of RepoDb v1.11.0, v1.0.7 I'm using, Insert(participant...) or Update(participant...) is working but If I switch to the latest version of RepoDb v1.11.3 and v.1.0.11-beta1 I have this error
{"Object reference not set to an instance of an object."}
at RepoDb.Extensions.PropertyInfoExtension.GetHandledValue(PropertyInfo property, Object entity, Type declaringType)
at RepoDb.Extensions.PropertyInfoExtension.GetHandledValue(PropertyInfo property, Object entity)
at RepoDb.Extensions.PropertyInfoExtension.AsQueryField(PropertyInfo property, Object entity, Boolean appendUnderscore)
at RepoDb.Extensions.PropertyInfoExtension.AsQueryField(PropertyInfo property, Object entity)
at RepoDb.DbConnectionExtension.ToQueryGroup[TEntity](ClassProperty property, TEntity entity)
at RepoDb.DbConnectionExtension.Update[TEntity](IDbConnection connection, TEntity entity, String hints, Nullable`1 commandTimeout, IDbTransaction transaction, ITrace trace, IStatementBuilder statementBuilder)
at repository.Save(Participant participant) in **********\Repository.cs:line 35
Best
Gilles
Hello Michael,
So currently, I'm using
RepoDb v1.11.0
RepoDbSqlServer v1.0.7
I'm having my domain entities deriving from this base class
Example
With my current version of RepoDb v1.11.0, v1.0.7 I'm using, Insert(participant...) or Update(participant...) is working but If I switch to the latest version of RepoDb v1.11.3 and v.1.0.11-beta1 I have this error
Best
Gilles