Andrius wrote:
Otis wrote:
CustomerEntity Oh sorry my bad
Fields returns IEntityFields of course, it's in the class, not in teh interface:
cloneCustomer.Fields = ((EntityFields)sourceCustomer.Fields).Clone();
It would be really nice if IEntityFields could extend all interfaces EntityFields does.
Same is true for other interfaces and classes
Then we could work with interfaces instead on abstract classes, which I think is better coding practice
I thought that too, so did MS back in 2003, but they moved towards base classes and away from interfaces. One of the reasons was that an interface can't be updated without breaking code, but a class can.
What they do today is implement as much interfaces explicitly and call from those methods into normal methods offered by the class itself.
I overdid the interface design in the framework a bit, which is caused by the fact that I first designed all the interfaces and then wrote code. The interfaces for entityfields and entityfield for example aren't that required, there's just 1 implementor.
So to recap: the interfaces should offer you a type definition which is a subset of the class type's interface. It's therefore not always wise to simply make an llblgen pro interface inherit from all interfaces defined on its implementor, as that's not always known. (in this case, it is, but it doesn't have to).
In this particular case the cast to the actual implementing type to be able to perform a clone is mitigating the purpose of the interface, which I agree with. However to keep the interfaces offer just the functionality the type represented by the interface should offer, I've to decide this on a type by type basis.
I'll try to make the proper decision which interfaces to inherit from for v2.0 so using interfaces is as painless as can be. Interfaces are sometimes required for generic programming with generics, how ironic that may sound, because generic code using generic types like an EntityCollection<T> also has to know what T is, which can create a huge complexity inside the code, as using IEntityCollection2 is much simpler.
Andrius wrote:
Otis wrote:
CustomerEntity sourceCustomer = new CustomerEntity("CHOPS");
CustomerEntity cloneCustomer = new CustomerEntity();
cloneCustomer.Fields = sourceCustomer.Fields.Clone();
should do the trick.
no related entities are copied though, just the entity's fields.
Is there a way to clone entity together with child enties and child entity collections?
So far we are using binary serialization for this purpose
No, sorry. Cloning is per entity.