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