WayneBrantley wrote:
They don't need the overloads, as the base collection has them. DeleteMulti(predicate) deletes directly, DeleteMulti() deletes the entities inside the collection.
Otis, I don't understand. I need to be able to call DeleteMulti(predicate) from an Entity that is part of a Hierachy and I cannot (it does not exist). I can call it for any Entity that is not part of a Hierachy.
Oh, my mistake! Yes, these don't exist. I'll explain why.
Say you have a hierarchy of targetperentity: Employee <- Manager. Say you want to delete all employees who manage a department X, which is an FK in manager.
So first you do:
delete from manager where managesdepartmentid = @x
this gives a set of N managers. Then you have to delete only the employee rows which match that N manager rows. But you can't, as these rows are gone. You can't do:
delete from employee where employeeid in (select managerid from manager where managesdepartmentid = @x)
As the delete of a hierarchical entity which spans multiple tables takes multiple deletes with a filter in this case, and you have to filter on rows which you had to delete first, this won't work. This was the reason the method wasn't added to the hierarchical code.
If it's not in the manual (it should), please let me know and I'll add it. This is a situation I ran into when I had the code in place and I had to take it out because it doesn't work. Ok, it sometimes works, but only if the filter is on the root entity of the hierarchy, which requires knowledge which fields are mapped onto which tables, IMHO that would leak abstraction info and which isn't good.
What you want is in the manual: Using the generated classes, using the entity classes, "Modifying an entity" -> 'option 2'.
MyEntity foo = new MyEntity();
foo.PkField = pkValue;
foo.IsNew = false;
foo.Delete();
Believe it or not I have read every line of your help files. The code you provided does not work, because the PkField is readonly - I guess I would have to do the ForcedCurrentValueWrite (which is discouraged)?
Selfservicing has an issue with readonly PK values if they're identity. This is because these fields aren't settable in the db. In that corner-case you need to set the PK with forcedcurrentvaluewrite.
Back to the original issue - This all seems crazy - I am having this issue because I do not have the same DeleteMulti() for Hierachial Entities as I do regular entities. Can you explain?
I hope the explanation above illustrates what the problem is and that there's no workaround for this particular issue. I know it kind of sucks, but there's not a satisfying solution to this.