Greetings,
i have the following problem:
for my domain model i have a base abstract class that override the equals and gethash code. I made this cause i work with NHibernate with differents unit of works, so i open and close session very often. At the bottom of topic you can find the class.
I found some problems using an observable collection that use the class inherited from ModelBase.
The problem arises when i use the ShowInsertRow on the gridview.
1. If i start adding a new row, if i cancel the process -> cannot see the added row, but it is in the observable collection and if i reorder the gridview i can see it.
2. For each row created (like that i would canceled in point 1, or just cause i had committed it) i cannot delete it.
Do you have any suggestion?
If i take on account to start use your orm, how is the best practice to manage this? does it need to override?
Thx in advance
Mauro
P.s.: sorry for my poor english, tell me if something is not clear
public abstract class ModelBase<TPKey> : dlcts.IModelBase<TPKey>, INotifyPropertyChanged {
///EDIT: eliminated wrong comment, Id is the PrimaryKey of the entity in the database
public virtual TPKey Id { get; set; }
/// <summary>
/// Return if the implementation of the PrimaryKey is not equals the default of its type
/// </summary>
public virtual bool IsPersisted { get { return !Id.Equals(default(TPKey)); } }
... omitted code
#region Equals-HashCode
/// <summary>
/// Check the equality of the PrimaryKey of 2 objects (if they are of the same type)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj) {
//with this line it is all ok
return base.Equals(obj);
//with these 4 lines i have the problems
ModelBase<TPKey> other = obj as ModelBase<TPKey>;
if (other == null) return false;
if (this.Id.Equals(default(TPKey)) || other.Id.Equals(default(TPKey))) return false;
return this.Id.Equals(other.Id);
}
/// <summary>
/// Return the HashCode of the primary key
/// </summary>
/// <returns></returns>
public override int GetHashCode() {
//with this line it is all ok
return base.GetHashCode();
//with this line i have the problem
return this.Id.GetHashCode();
}
#endregion
}
i have the following problem:
for my domain model i have a base abstract class that override the equals and gethash code. I made this cause i work with NHibernate with differents unit of works, so i open and close session very often. At the bottom of topic you can find the class.
I found some problems using an observable collection that use the class inherited from ModelBase.
The problem arises when i use the ShowInsertRow on the gridview.
1. If i start adding a new row, if i cancel the process -> cannot see the added row, but it is in the observable collection and if i reorder the gridview i can see it.
2. For each row created (like that i would canceled in point 1, or just cause i had committed it) i cannot delete it.
Do you have any suggestion?
If i take on account to start use your orm, how is the best practice to manage this? does it need to override?
Thx in advance
Mauro
P.s.: sorry for my poor english, tell me if something is not clear
public abstract class ModelBase<TPKey> : dlcts.IModelBase<TPKey>, INotifyPropertyChanged {
///EDIT: eliminated wrong comment, Id is the PrimaryKey of the entity in the database
public virtual TPKey Id { get; set; }
/// <summary>
/// Return if the implementation of the PrimaryKey is not equals the default of its type
/// </summary>
public virtual bool IsPersisted { get { return !Id.Equals(default(TPKey)); } }
... omitted code
#region Equals-HashCode
/// <summary>
/// Check the equality of the PrimaryKey of 2 objects (if they are of the same type)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj) {
//with this line it is all ok
return base.Equals(obj);
//with these 4 lines i have the problems
ModelBase<TPKey> other = obj as ModelBase<TPKey>;
if (other == null) return false;
if (this.Id.Equals(default(TPKey)) || other.Id.Equals(default(TPKey))) return false;
return this.Id.Equals(other.Id);
}
/// <summary>
/// Return the HashCode of the primary key
/// </summary>
/// <returns></returns>
public override int GetHashCode() {
//with this line it is all ok
return base.GetHashCode();
//with this line i have the problem
return this.Id.GetHashCode();
}
#endregion
}