DeleteSelfChild - Parent is null after updating from 8.2.9 to 9.1.0 #4759
-
|
We're trying to update from Csla 8.2.9 to 9.1.0, and immediately hit an issue in a DeleteSelfChild method; we're trying to use the Parent property to get to the root object to get its Id, but it seems like this is null now. Was this intentional or is it a bug? If its intentional, what would be the proposed workaround? I'd rather not have to add an id property to every child instance and keep it in sync with the parent. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hi. That's a bug. The for deletion marked child should still know it's parent. using Csla;
using Csla.Configuration;
using Csla.Serialization;
using Microsoft.Extensions.DependencyInjection;
using var sp = new ServiceCollection()
.AddCsla()
.BuildServiceProvider();
var rootPortal = sp.GetRequiredService<IDataPortal<Root>>();
var root = await rootPortal.FetchAsync();
//root.Delete();
root.Childs.RemoveAt(0);
//var formatter = SerializationFormatterFactory.GetFormatter(sp.GetRequiredService<ApplicationContext>()); // CSLA 8.X
var formatter = sp.GetRequiredService<ISerializationFormatter>(); // CSLA 9.x+
var data = formatter.Serialize(root);
var deserialized = formatter.Deserialize(data);
_ = deserialized; // here the child in the Childs.DeletedList should still have it's parent set
[CslaImplementProperties, Serializable]
public partial class Root : BusinessBase<Root> {
public partial Guid Id { get; set; }
public partial FooChilds Childs { get; set; }
[Fetch]
private async Task Fetch([Inject] IChildDataPortal<FooChilds> fooPortal) {
Id = Guid.NewGuid();
Childs = await fooPortal.FetchChildAsync();
}
[Update]
[DeleteSelf]
private async Task DeleteSelf() {
await FieldManager.UpdateAllChildrenAsync();
}
}
[Serializable]
public partial class FooChilds : BusinessListBase<FooChilds, FooChild> {
[FetchChild]
private async Task FetchChild([Inject] IChildDataPortal<FooChild> fooPortal) {
for (int i = 0; i < 3; i++) {
Add(await fooPortal.FetchChildAsync());
}
}
}
[CslaImplementProperties, Serializable]
public partial class FooChild : BusinessBase<FooChild> {
public partial Guid? Id { get; set; }
[FetchChild]
private void CreateChild() {
Id = Guid.NewGuid();
}
[DeleteSelfChild]
private void DeleteSelfChild() {
Id = null;
}
[UpdateChild]
private void UpdateChild() {
_ = this;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Created a bug out of this discussion: #4761 |
Beta Was this translation helpful? Give feedback.
Hi. That's a bug. The for deletion marked child should still know it's parent.
I can reproduce this issue with this code: