Skip to content

Commit 79b3a66

Browse files
committed
Fix .net 9 / C# 14 Entity Framework bugs Delete-App in Oqtane
2sic/2sxc#3584
1 parent 51c54b3 commit 79b3a66

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

ToSic.Eav.Repository.Efc/Parts/DbApp.cs

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ToSic.Eav.Apps.Internal.Specs;
22
using ToSic.Eav.Serialization;
33
using JsonSerializer = System.Text.Json.JsonSerializer;
4+
// ReSharper disable InvokeAsExtensionMethod
45

56
namespace ToSic.Eav.Repository.Efc.Parts;
67

@@ -102,38 +103,60 @@ internal void DeleteApp(int appId, bool fullDelete)
102103
private void DeleteAppWithoutStoredProcedure(int appId, bool alsoDeleteAppEntry)
103104
{
104105
var db = DbContext.SqlDb;
105-
var appContentTypes = db.ToSicEavAttributeSets.Where(a => a.AppId == appId).ToList();
106-
var contentTypeIds = appContentTypes.Select(ct => ct.AttributeSetId).ToArray();
106+
var appContentTypes = db.ToSicEavAttributeSets
107+
.Where(a => a.AppId == appId)
108+
.ToList();
109+
var contentTypeIds = appContentTypes
110+
.Select(ct => ct.AttributeSetId)
111+
.ToArray();
107112

108113
// WIP v13 - now with Inherited Apps, we have entities which point to a content-type which doesn't belong to the App itself
109114
const bool useV12Method = false;
110115
var appEntities = useV12Method
111-
? db.ToSicEavEntities.Where(e => appContentTypes.Contains(e.AttributeSet))
116+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
117+
//? db.ToSicEavEntities.Where(e => appContentTypes.Contains(e.AttributeSet))
118+
? db.ToSicEavEntities.Where(e => Enumerable.Contains(appContentTypes, e.AttributeSet))
112119
: db.ToSicEavEntities.Where(e => e.AppId == appId);
113120

114121
var entityIds = appEntities.Select(e => e.EntityId).ToArray();
115122

116123
// Delete Value-Dimensions
117-
var appValues = db.ToSicEavValues.Where(v => entityIds.Contains(v.EntityId));
118-
var appValueIds = appValues.Select(a => a.ValueId).ToList();
119-
var valDimensions = db.ToSicEavValuesDimensions.Where(vd => appValueIds.Contains(vd.ValueId));
124+
var appValues = db.ToSicEavValues
125+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
126+
//.Where(v => entityIds.Contains(v.EntityId));
127+
.Where(v => Enumerable.Contains(entityIds, v.EntityId));
128+
var appValueIds = appValues
129+
.Select(a => a.ValueId)
130+
.ToList();
131+
var valDimensions = db.ToSicEavValuesDimensions
132+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
133+
//.Where(vd => appValueIds.Contains(vd.ValueId));
134+
.Where(vd => Enumerable.Contains(appValueIds, vd.ValueId));
120135
db.RemoveRange(valDimensions);
121136
db.RemoveRange(appValues.ToList());
122137

123138

124139
// Delete Parent-EntityRelationships & Child-EntityRelationships
125140
var dbRelTable = db.ToSicEavEntityRelationships;
126-
var relationshipsWithAppParents = dbRelTable.Where(rel => entityIds.Contains(rel.ParentEntityId));
141+
var relationshipsWithAppParents = dbRelTable
142+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
143+
//.Where(rel => entityIds.Contains(rel.ParentEntityId));
144+
.Where(rel => Enumerable.Contains(entityIds, rel.ParentEntityId));
127145
db.RemoveRange(relationshipsWithAppParents.ToList());
128-
var relationshipsWithAppChildren = dbRelTable.Where(rel => entityIds.Contains(rel.ChildEntityId ?? -1));
146+
var relationshipsWithAppChildren = dbRelTable
147+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
148+
//.Where(rel => entityIds.Contains(rel.ChildEntityId ?? -1));
149+
.Where(rel => Enumerable.Contains(entityIds, rel.ChildEntityId ?? -1));
129150
db.RemoveRange(relationshipsWithAppChildren.ToList());
130151

131152
// Delete Entities
132153
db.RemoveRange(appEntities);
133154

134155
// Delete Attributes
135-
var attributeSetMappings =
136-
db.ToSicEavAttributesInSets.Where(aInS => contentTypeIds.Contains(aInS.AttributeSetId));
156+
var attributeSetMappings = db.ToSicEavAttributesInSets
157+
// commented because of https://github.com/npgsql/efcore.pg/issues/3461, we can go back with net10.0
158+
//.Where(aInS => contentTypeIds.Contains(aInS.AttributeSetId));
159+
.Where(aInS => Enumerable.Contains(contentTypeIds, aInS.AttributeSetId));
137160
var attributes = attributeSetMappings.Select(asm => asm.Attribute);
138161
db.RemoveRange(attributes.ToList());
139162

0 commit comments

Comments
 (0)