CliffH wrote:
OK here's my problem: I have a system which has a series of 1:1 relationships: in LLBLGen I have an inheritance heirarchy. I have no issues with LLBLGen Desogmer: the sub-type / super_types are visible, clearly indicated as 1:1 relationships.
The question is, IN CODE, what do I do to create an instance of an entity supertype / subtype. The docs are long on theory but short on examples of this. it seems to me that I can't just create a subtype instance and expect to be able to populate the supertype, e.g.,
HotelEntity hotel = new HotelEntity()
Of course you can
Every type in your inheritance hierarchy is just an entity. Thus, you can instantiate these entities in code by code like you typed above, except if the type is marked as abstract.
I also need ServiceEntity service = new ServiceEntity();
OK, I do this, but then I end up with 2 entities where I would expect one.
In another post, you explained your inheritance hierarchy, so Hotel is a subtype of Service.
Now, if I want to instantiate a hotelentity, I just do:
HotelEntity hotel = new HotelEntity(1234);
and I'll instantiate the hotel entity with PK 1234. If you're using adapter, it's not fetched yet, so if I want to fetch it I have to do:
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(hotel);
I then can do:
ServiceEntity hotelAsService = (ServiceEntity)hotel;
because, HotelEntity derives from ServiceEntity.
If this is expected then how do I persist this (these) entities ?
Just as normal entities. A HotelEntity is-a ServiceEntity, because it uses inheritance. So if you fill the HotelEntity's fields, you can save it like any other entity. The serviceentity's fields are inside that HotelEntity, as it uses inheritance.
I have no problem with 1:n relationships - I can create these and save these recursively using adapter.SaveEntity( entityname, true).
Any suggestions.
So in the example above:
HotelEntity hotel = new HotelEntity(1234);
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntity(hotel);
hotel.Name = "The New Hotel Name";
// save it:
adapter.SaveEntity(hotel);