Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Another 'Newbie' question - 1:1 relationships
 

Pages: 1
LLBLGen Pro Runtime Framework
Another 'Newbie' question - 1:1 relationships
Page:1/1 

  Print all messages in this thread  
Poster Message
CliffH
User



Location:

Joined on:
03-May-2006 14:27:07
Posted:
52 posts
# Posted on: 20-May-2006 16:08:19.  
Using adapter. Have project in which target per entities have been created. I have some 1:1 relationships which clearly show in the designer, e.g., hotel, car, insurance (subtype of 'Service'). BTW it's the travel domain, where service is a generalisation and the subtypes hotel, car, insurance plus a few more. I can see the inheritance info and can collapse / expand e.g., the hotel entity, which clearly shows the columns in the parent 'service' entity as well as the sub-type's fields.

Searched the docs but need a quick code example to get me going: instantiate e.g., a hotel entity. From what I can understand, instantiating a hotel entity should allow me to see the details of the 'service' entity .... or should I be doing it the other way round.

Any quick easy suggestions appreciated.
  Top
sparmar2000
User



Location:
Aylesbury, UK
Joined on:
30-Nov-2003 14:50:22
Posted:
341 posts
# Posted on: 20-May-2006 18:57:48.  
Quote:
I can see the inheritance info and can collapse / expand e.g., the hotel entity, which clearly shows the columns in the parent 'service' entity as well as the sub-type's fields.


Not quite clear what you mean by this, but I presume you can see this from a control that is bound to a collection.

If this is that case then you sohuld be able to see the generated code in your project lumped under a Region "Windows Form Designer generated code". (Normaly I 'manufacture' a senerio here just to create example codes)


  Top
CliffH
User



Location:

Joined on:
03-May-2006 14:27:07
Posted:
52 posts
# Posted on: 21-May-2006 05:51:19.  
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()

I also need ServiceEntity service = new ServiceEntity();

OK, I do this, but then I end up with 2 entities where I would expect one.

If this is expected then how do I persist this (these) entities ?

I have no problem with 1:n relationships - I can create these and save these recursively using adapter.SaveEntity( entityname, true).

Any suggestions.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37372 posts
# Posted on: 22-May-2006 11:34:41.  
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 Regular Smiley
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.

Quote:

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.

Quote:

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.

Quote:

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);


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
CliffH
User



Location:

Joined on:
03-May-2006 14:27:07
Posted:
52 posts
# Posted on: 22-May-2006 15:19:58.  
Many thanks for this. I did the following test code and did a recursive save without problem. Your suggestion should move me on quite a bit. The solution wasn't easy, intuitive, now it is obvious. Maybe you could add it to the "How To'" for future. You can close this thread.

If you could respond to my other open thread re. reference / lookup data.

BookingEntity booking = new BookingEntity();
booking.BookingDate = DateTime.Now;
booking.AppUser_ID = AppInstance.User_ID;
booking.CreationDate = DateTime.Now;
booking.Client_ID = 1;
booking.BookingSource_ID = 10;
booking.BookingStatus_ID = 3;

PassengerEntity pax = new PassengerEntity();
pax.PassengerType_ID = 1;
pax.Title = "Mr";
pax.Initials_Forename = "C";
pax.Surname = "Test";
pax.LeadPassenger = true;
booking.Passenger.Add( pax );

pax = new PassengerEntity();
pax.PassengerType_ID = 1;
pax.Title = "Mrs";
pax.Initials_Forename = "D";
pax.Surname = "Test";
pax.LeadPassenger = false;
booking.Passenger.Add( pax );
pax = new PassengerEntity();
pax.PassengerType_ID = 2;
pax.Title = "Miss";
pax.Initials_Forename = "E";
pax.Surname = "Test";
pax.LeadPassenger = false;
booking.Passenger.Add( pax );

HotelEntity hotel = new HotelEntity();
ServiceEntity hotelservice = (ServiceEntity)hotel;

hotelservice.ServiceType_ID = 9;
hotelservice.Vendor_ID = 100;
hotelservice.VendorRef = "TC19293949";
hotelservice.DeparturePoint_ID = 912;
hotelservice.DepartureDate = DateTime.Now;
hotelservice.DepartureTime = "12:00";
hotelservice.ArrivalPoint_ID = 1;
hotelservice.ArrivalDate = DateTime.Now;
hotelservice.ArrivalTime = "15:25";
hotelservice.Duration = 5;
hotelservice.Status = "OK";
hotelservice.Note = "Hotel service note";
hotelservice.IsPrintableOnInvoice = false;
hotelservice.IsPrintableOnItinerary = true;
hotel.RoomName_ID = 1;
hotel.RoomType_ID = 3;
hotel.MealPlan_ID = 3;
hotel.HotelName = "Delhi Plaza";
hotel.HotelAddress = "Not Known";
hotel.SpecialRequest = "None";
hotel.Note = "Hotel Note";
hotel.PropertyCode = 1;
            
booking.Service.Add( hotelservice);
booking.Service.Add( hotel );

DataAccessAdapter adapter = new DataAccessAdapter();
bool IsSaved = adapter.SaveEntity( booking, true );
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.