LLBLGen or not LLBLGen

Posts   
 
    
Khou
User
Posts: 46
Joined: 28-Mar-2009
# Posted on: 28-Mar-2009 06:28:48   

LLBLGen or not LLBLGen (ORM or not ORM)

I have never used a ORM tool before, thinking of giving LLBLGen a go, (rather than LINQ) but have a few example/questions

Example If a phone number to has 3 types (Home,Work & Mobile) Normally I would create 2 physical entity tables -Phone and -PhoneType

OR 1 physical entity called "Phone" and create 3 flag columns "isHome", "isWork", and "isMobile".

OR 1 physical entity called "Phone" with 2 columns (PhoneNumber,PhoneType)

After that I would write some SQL to get it working...and manually blind the data.

Now a ORM tool such as LLBLGen, it seems i have to think differently, I would only now need to create 1 entity called "Phone" then create subtype HomePhone, WorkPhone, MobilePhone, which are not physically mapped in my database.

I can see how this can benefit, speed up development but I feel like I'm loosing some control. ie 1 - How can i write a SQL query to get what i want anymore if everything is mapped via objects? 2 - what about performance? 3 - what about if i run multiple applications using 1 database, i.e how would other applications know , which data is my home number or work number or mobile number?

Khou
User
Posts: 46
Joined: 28-Mar-2009
# Posted on: 28-Mar-2009 06:39:37   

Do I need to think and design my database differently to work properly with LLBLGen?

Is there a way LLBLGen likes me to design my database?

Khou
User
Posts: 46
Joined: 28-Mar-2009
# Posted on: 28-Mar-2009 07:20:08   

could someone give a quick example how to use LLBLGen? say you two two physical entity (Phone and PhoneType) [see below]

now you want to list all phone number and its type. What do you do?

Phone
-PKPhoneID
-FKPhoneTYPEID
-PhoneNumber
-PhoneExt

PhoneType
-PKPhoneTypeID
-Name
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 28-Mar-2009 10:47:10   

Khou wrote:

could someone give a quick example how to use LLBLGen? say you two two physical entity (Phone and PhoneType) [see below]

now you want to list all phone number and its type. What do you do?

Phone
-PKPhoneID
-FKPhoneTYPEID
-PhoneNumber
-PhoneExt

PhoneType
-PKPhoneTypeID
-Name

You can do that in two ways - create the two entities, and use a prefetch path to fetch both at the same time, so fetch PhoneEntity instances and also PhoneTypeEntity instances. This could be done using:


PrefetchPath2 path = new PrefetchPath2(EntityType.PhoneEntity);
path.Add(PhoneEntity.PrefetchPathPhoneType);
EntityCollection<PhoneEntity> phones = new EntityCollection<PhoneEntity>();
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(phones, null, path);
}

(this is with 'adapter', selfservicing works a bit different but also uses prefetch paths). I assume you have at least peeked a bit into the documentation as it would be a bit silly to rehash that here wink )

This gives a list of phone entities and the related type. If you want to bind them to a grid and want to display the phonetype.name in that list as well, you could add in the designer for the PhoneEntity (open it in the editor) a Field mapped onto related fields (as it has a m:1 relationship with PhoneType) to PhoneType.name. If you use the above code and bind the 'phones' collection to a grid, you'll now see the Name as well.

If you just want to use a readonly list, you can also create a typed list in the designer with phone and phonetype (please see the documentation about typed lists). If you want to construct the list in-code you can too, simply create a dynamic list.

Of course you can also create a dynamic list in code with linq: (adapter)


using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    LinqMetaData metaData = new LinqMetaData(adapter);
    var q = from p in metaData.Phone
            select new {p.PKPhoneID, p.PhoneNumber, p.PhoneExt, p.PhoneType.Name } ;
    // do something with the list in q here. 
}

Please check out our examples at the website and our documentation for more information. It's a large set of features and it will take time to learn everything, however it's not necessary to learn everything to get data out of the db, just check the examples to see how to do certain basic things to get started and go from there. Good luck.

Frans Bouma | Lead developer LLBLGen Pro
Khou
User
Posts: 46
Joined: 28-Mar-2009
# Posted on: 03-Apr-2009 00:49:45   

thanks Otis